Skip to content

Commit

Permalink
Make Pants goal run for Python exit with error code 1 if the python
Browse files Browse the repository at this point in the history
program exits non-zero (as pants goal run does for java).

Testing Done:
Ran new tests.

Reviewed at https://rbcommons.com/s/twitter/r/1374/
  • Loading branch information
dturner-tw committed Nov 22, 2014
1 parent 4f36df6 commit 4399efc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/python/pants/backend/python/tasks/python_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ def execute(self):
pex = PEX(builder.path(), interpreter=interpreter)
self.context.lock.release()
with self.context.new_workunit(name='run', labels=[WorkUnit.RUN]):
po = pex.run(blocking=False, args=self.get_options().args + self.get_passthru_args())
args = self.get_options().args + self.get_passthru_args()
po = pex.run(blocking=False, args=args)
try:
return po.wait()
result = po.wait()
if result != 0:
raise TaskError('python {args} ... exited non-zero ({code})' %
dict(args=args, code=result),
exit_code=result)
except KeyboardInterrupt:
po.send_signal(signal.SIGINT)
raise
15 changes: 15 additions & 0 deletions tests/python/pants_test/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,18 @@ python_binary(
entry_point = 'pants_test.python.echo_interpreter_version',
compatibility = ['CPython<2.6']
)

python_library(
name = 'die_lib',
sources = ['die.py'],
dependencies = [],
compatibility = ['CPython>=2.6,<3']
)

python_binary(
name = 'die',
dependencies = [
':die_lib',
],
entry_point = 'pants_test.python.die',
)
12 changes: 12 additions & 0 deletions tests/python/pants_test/python/die.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals)

import sys


print('Exiting with status 1')
sys.exit(1)
7 changes: 7 additions & 0 deletions tests/python/pants_test/python/test_python_run_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def test_run_26(self):
def test_run_27(self):
self._maybe_run_version('2.7')

def test_die(self):
command = ['goal', 'run', 'tests/python/pants_test/python:die'
'--interpreter=CPython>=2.6,<3',
'--interpreter=CPython>=3.3', '--quiet']
pants_run = self.run_pants(command=command)
assert pants_run.returncode == 1

def _maybe_run_version(self, version):
if self.has_python_version(version):
print('Found python %s. Testing running on it.' % version)
Expand Down

0 comments on commit 4399efc

Please sign in to comment.