-
-
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
console_rules can exit with exit codes #6654
Merged
illicitonion
merged 5 commits into
pantsbuild:master
from
twitter:dwagnerhall/v2/gracefultermination
Oct 19, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
403b7e6
Give useful description of which version of a test failed
illicitonion 1d280db
console_rules can exit with exit codes
illicitonion 975d5ac
Review comments
illicitonion e3fc124
Move GracefulTerminationException to a new package
illicitonion 802e6eb
Add TODO
illicitonion 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
14 changes: 14 additions & 0 deletions
14
pants-plugins/src/python/internal_backend/rules_for_testing/BUILD
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,14 @@ | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_library( | ||
name = 'plugin', | ||
sources = ['__init__.py', 'register.py'], | ||
dependencies = [ | ||
'src/python/pants/base:exceptions', | ||
'src/python/pants/engine:addressable', | ||
'src/python/pants/engine:console', | ||
'src/python/pants/engine:rules', | ||
'src/python/pants/engine:selectors', | ||
] | ||
) |
Empty file.
23 changes: 23 additions & 0 deletions
23
pants-plugins/src/python/internal_backend/rules_for_testing/register.py
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,23 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from pants.engine.addressable import BuildFileAddresses | ||
from pants.engine.console import Console | ||
from pants.engine.rules import console_rule | ||
from pants.engine.selectors import Select | ||
from pants.rules.core.exceptions import GracefulTerminationException | ||
|
||
|
||
@console_rule('list-and-die-for-testing', [Select(Console), Select(BuildFileAddresses)]) | ||
def fast_list_and_die_for_testing(console, addresses): | ||
"""A fast variant of `./pants list` with a reduced feature set.""" | ||
for address in addresses.dependencies: | ||
console.print_stdout(address.spec) | ||
raise GracefulTerminationException(exit_code=42) | ||
|
||
|
||
def rules(): | ||
return (fast_list_and_die_for_testing,) |
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,30 @@ | ||
# coding=utf-8 | ||
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
|
||
class GracefulTerminationException(Exception): | ||
"""Indicates that a console_rule should eagerly terminate the run. | ||
|
||
No error trace will be printed if this is raised; the runner will simply exit with the passed | ||
exit code. | ||
|
||
Nothing except a console_rule should ever raise this. | ||
""" | ||
|
||
def __init__(self, message='', exit_code=1): | ||
""" | ||
:param int exit_code: an optional exit code (default=1) | ||
""" | ||
super(GracefulTerminationException, self).__init__(message) | ||
|
||
if exit_code == 0: | ||
raise ValueError("Cannot create GracefulTerminationException with exit code of 0") | ||
|
||
self._exit_code = exit_code | ||
|
||
@property | ||
def exit_code(self): | ||
return self._exit_code |
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
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.
Mmmm... this bit of magic is unpleasant.
It almost makes me wonder whether we shouldn't have a separate/explicit Scheduler entrypoint for
@console_rule
? Would likely be useful for @wisechengyi's UX PR.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.
Added a TODO for now