-
-
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.
- Loading branch information
1 parent
4884683
commit aaf8692
Showing
11 changed files
with
104 additions
and
3 deletions.
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