-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create infrastructure for running interactive local process #8495
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6dc097f
make keyboardinterrupt capturing in rules work
cosmicexplorer d95a54e
clean up and make code correct
cosmicexplorer d7b1940
use list .pop(0) and remove deque
cosmicexplorer f5700e5
Create InteractiveRunner type + run @console_rule
gshuflin 9bf0fd0
Handle SIGINT in python
gshuflin 3e30b2c
Get rid of enum for controlling where subprocess executes
gshuflin c5648c3
Fix BUILD file and dependencies
gshuflin 5a87acd
Respond to PR
gshuflin 48538e1
use tuples()
gshuflin e1bace0
Need to fix the build file again.
gshuflin 81a7f66
Fix type error in toggle method
gshuflin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message here appears to be the negation of the if condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from one of the commits @cosmicexplorer had in his currently-open-PR that I rebased off of becuase the bug he fixed was affecting me. I'm not sure if makes sense to try to get that merged and then merge this PR after that, or just merge this one with those commits.