Commit d3768f4a authored by jim's avatar jim

Bug fixed:

  The standard Python -m option didn't work for custom interpreters.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@103354 62d5b8a3-27da-0310-9561-8e5933582275
parent 74ef430b
...@@ -22,6 +22,8 @@ Bugs fixed: ...@@ -22,6 +22,8 @@ Bugs fixed:
- Scripts run using generated interpreters didn't have __file__ set correctly. - Scripts run using generated interpreters didn't have __file__ set correctly.
- The standard Python -m option didn't work for custom interpreters.
1.4.0 (2009-08-26) 1.4.0 (2009-08-26)
================== ==================
......
...@@ -1127,23 +1127,28 @@ sys.path[0:0] = [ ...@@ -1127,23 +1127,28 @@ sys.path[0:0] = [
_interactive = True _interactive = True
if len(sys.argv) > 1: if len(sys.argv) > 1:
import getopt _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_options, _args = getopt.getopt(sys.argv[1:], 'ic:')
_interactive = False _interactive = False
for (_opt, _val) in _options: for (_opt, _val) in _options:
if _opt == '-i': if _opt == '-i':
_interactive = True _interactive = True
elif _opt == '-c': elif _opt == '-c':
exec _val exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
if _args: if _args:
sys.argv[:] = _args sys.argv[:] = _args
__file__ = _args[0] __file__ = _args[0]
del _options, _args
execfile(__file__) execfile(__file__)
if _interactive: if _interactive:
import code del _interactive
code.interact(banner="", local=globals()) __import__("code").interact(banner="", local=globals())
''' '''
runsetup_template = """ runsetup_template = """
......
...@@ -663,32 +663,38 @@ the path set: ...@@ -663,32 +663,38 @@ the path set:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE >>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4 #!/usr/local/bin/python2.4
<BLANKLINE>
import sys import sys
<BLANKLINE> <BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg', '/sample-install/demo-0.3-pyN.N.egg',
'/sample-install/demoneeded-1.1-py2.4.egg', '/sample-install/demoneeded-1.1-pyN.N.egg',
] ]
<BLANKLINE> <BLANKLINE>
_interactive = True _interactive = True
if len(sys.argv) > 1: if len(sys.argv) > 1:
import getopt _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_options, _args = getopt.getopt(sys.argv[1:], 'ic:')
_interactive = False _interactive = False
for (_opt, _val) in _options: for (_opt, _val) in _options:
if _opt == '-i': if _opt == '-i':
_interactive = True _interactive = True
elif _opt == '-c': elif _opt == '-c':
exec _val exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE> <BLANKLINE>
if _args: if _args:
sys.argv[:] = _args sys.argv[:] = _args
__file__ = _args[0] __file__ = _args[0]
del _options, _args
execfile(__file__) execfile(__file__)
<BLANKLINE> <BLANKLINE>
if _interactive: if _interactive:
import code del _interactive
code.interact(banner="", local=globals()) __import__("code").interact(banner="", local=globals())
If invoked with a script name and arguments, it will run that script, instead. If invoked with a script name and arguments, it will run that script, instead.
...@@ -701,6 +707,15 @@ If invoked with a script name and arguments, it will run that script, instead. ...@@ -701,6 +707,15 @@ If invoked with a script name and arguments, it will run that script, instead.
['ascript', 'a', 'b', 'c'] ['ascript', 'a', 'b', 'c']
('__main__', 'ascript', 'demo doc') ('__main__', 'ascript', 'demo doc')
For Python 2.5 and higher, you can also use the -m option to run a
module:
>>> print system(join(bin, 'py')+' -m pdb'),
usage: pdb.py scriptfile [arg] ...
>>> print system(join(bin, 'py')+' -m pdb what'),
Error: what does not exist
An additional argument can be passed to define which scripts to install An additional argument can be passed to define which scripts to install
and to provide script names. The argument is a dictionary mapping and to provide script names. The argument is a dictionary mapping
original script names to new script names. original script names to new script names.
...@@ -873,23 +888,28 @@ We specified an interpreter and its paths are adjusted too: ...@@ -873,23 +888,28 @@ We specified an interpreter and its paths are adjusted too:
<BLANKLINE> <BLANKLINE>
_interactive = True _interactive = True
if len(sys.argv) > 1: if len(sys.argv) > 1:
import getopt _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_options, _args = getopt.getopt(sys.argv[1:], 'ic:')
_interactive = False _interactive = False
for (_opt, _val) in _options: for (_opt, _val) in _options:
if _opt == '-i': if _opt == '-i':
_interactive = True _interactive = True
elif _opt == '-c': elif _opt == '-c':
exec _val exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE> <BLANKLINE>
if _args: if _args:
sys.argv[:] = _args sys.argv[:] = _args
__file__ = _args[0] __file__ = _args[0]
del _options, _args
execfile(__file__) execfile(__file__)
<BLANKLINE> <BLANKLINE>
if _interactive: if _interactive:
import code del _interactive
code.interact(banner="", local=globals()) __import__("code").interact(banner="", local=globals())
Handling custom build options for extensions provided in source distributions Handling custom build options for extensions provided in source distributions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment