Skip to content

Commit

Permalink
Enable passthru args for python run.
Browse files Browse the repository at this point in the history
Also enabled an explicit flag for this, which we shockingly didn't have before somehow.

Made some changes to example code to allow manual testing of this. Try:

./pants goal run.py --args="benjy"  examples/src/python/example/hello/main/ -- zundel jsirois

Changed the python run task's registration name from 'python-run' to 'py',  so that the cmd-line
scope is run.py instead of run.python_run.

Also added some missing __init__.py files.

Reviewed at https://rbcommons.com/s/twitter/r/1321/
  • Loading branch information
benjyw authored and Benjy committed Nov 12, 2014
1 parent e18733b commit c5150bf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Empty file.
Empty file.
7 changes: 6 additions & 1 deletion examples/src/python/example/hello/main/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from __future__ import (nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals)

import sys

from example.hello.greet.greet import greet


if __name__ == '__main__':
print(greet('world'))
greetees = sys.argv[1:] or ['world']
for greetee in greetees:
print(greet(greetee))
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def register_goals():
dependencies=['bootstrap', 'check-exclusives', 'resources']
).install('test')

task(name='python-run', action=PythonRun,
task(name='py', action=PythonRun,
dependencies=['bootstrap', 'check-exclusives', 'resources']
).install('run')

Expand Down
11 changes: 10 additions & 1 deletion src/python/pants/backend/python/tasks/python_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class PythonRun(PythonTask):
def __init__(self, *args, **kwargs):
super(PythonRun, self).__init__(*args, **kwargs)

@classmethod
def register_options(cls, register):
super(PythonRun, cls).register_options(register)
register('--args', action='append', help='Run with these extra args to main().')

@classmethod
def supports_passthru_args(cls):
return True

def execute(self):
binary = self.require_single_root_target()
if isinstance(binary, PythonBinary):
Expand All @@ -39,7 +48,7 @@ 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)
po = pex.run(blocking=False, args=self.get_options().args + self.get_passthru_args())
try:
return po.wait()
except KeyboardInterrupt:
Expand Down

0 comments on commit c5150bf

Please sign in to comment.