-
-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create infrastructure for running interactive local process (#8495)
## Problem pants run and pants repl (and perhaps other goals) have as their "output" the actual execution of a program, locally and interactively, which the current ExecuteProcessRequest infrastructure isn't designed to handle well. ## Solution This commit introduces a new type InteractiveRunner, which works like Console and Workspace, in that it can be requested only by a @console_rule and offers a blocking method to kick off an interactive subprocess, that takes control of the terminal. This commit also happens to include the stub of a v2 run @console_rule (called, currently, v2-run), which is a stub that just runs /usr/bin/python and was only included to test the rule - eventually this will become a full-featured v2 run goal.
- Loading branch information
Showing
16 changed files
with
225 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Tuple | ||
|
||
from pants.base.exception_sink import ExceptionSink | ||
from pants.engine.rules import RootRule | ||
|
||
|
||
@dataclass(frozen=True) | ||
class InteractiveProcessResult: | ||
process_exit_code: int | ||
|
||
|
||
@dataclass(frozen=True) | ||
class InteractiveProcessRequest: | ||
argv: Tuple[str, ...] | ||
env: Tuple[str, ...] = () | ||
run_in_workspace: bool = False | ||
|
||
|
||
@dataclass(frozen=True) | ||
class InteractiveRunner: | ||
_scheduler: Any | ||
|
||
def run_local_interactive_process(self, request: InteractiveProcessRequest) -> InteractiveProcessResult: | ||
ExceptionSink.toggle_ignoring_sigint_v2_engine(True) | ||
return self._scheduler.run_local_interactive_process(request) | ||
|
||
|
||
def create_interactive_runner_rules(): | ||
return [RootRule(InteractiveRunner)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from pants.engine.addressable import BuildFileAddresses | ||
from pants.engine.console import Console | ||
from pants.engine.goal import Goal | ||
from pants.engine.interactive_runner import InteractiveProcessRequest, InteractiveRunner | ||
from pants.engine.rules import console_rule | ||
|
||
|
||
class Run(Goal): | ||
"""Runs a runnable target.""" | ||
name = 'v2-run' | ||
|
||
|
||
@console_rule | ||
def run(console: Console, runner: InteractiveRunner, build_file_addresses: BuildFileAddresses) -> Run: | ||
console.write_stdout("Running the `run` goal\n") | ||
|
||
request = InteractiveProcessRequest( | ||
argv=["/usr/bin/python"], | ||
env=("TEST_ENV", "TEST"), | ||
run_in_workspace=False, | ||
) | ||
|
||
try: | ||
res = runner.run_local_interactive_process(request) | ||
print(f"Subprocess exited with result: {res.process_exit_code}") | ||
yield Run(res.process_exit_code) | ||
except Exception as e: | ||
print(f"Exception when running local interactive process: {e}") | ||
yield Run(-1) | ||
|
||
|
||
def rules(): | ||
return [run] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.