Commit 4852622c authored by Jim Fulton's avatar Jim Fulton

Improved the generated "py" scripts. These let you start Python with

the path set to include a set of distributions and their
dependeoncies. Now, you can also pass a script and arguments.  This
gives me a handy way of invoking setup.py scripts that require
setuptools without having to install setuptools into my system
python. :)
parent 8de0c625
...@@ -88,15 +88,24 @@ And the generated scripts invoke Python 2.3: ...@@ -88,15 +88,24 @@ And the generated scripts invoke Python 2.3:
eggrecipedemo.main() eggrecipedemo.main()
>>> f = open(os.path.join(sample_buildout, 'bin', 'py_demo')) >>> f = open(os.path.join(sample_buildout, 'bin', 'py_demo'))
>>> f.readline().strip() == '#!' + python2_3_executable + ' -i' >>> f.readline().strip() == '#!' + python2_3_executable
True True
>>> print f.read(), >>> print f.read(),
<BLANKLINE>
import sys import sys
<BLANKLINE>
if len(sys.argv) == 1:
import os
# Restart with -i
os.execl(sys.executable, sys.executable, '-i', sys.argv[0], '')
<BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
'/tmp/tmpOBTxDMsample-buildout/eggs/demo-0.2-py2.3.egg', '/tmp/tmpiIJY3Ysample-buildout/eggs/demo-0.2-py2.3.egg',
'/tmp/tmpOBTxDMsample-buildout/eggs/demoneeded-1.1-py2.3.egg' '/tmp/tmpiIJY3Ysample-buildout/eggs/demoneeded-1.1-py2.3.egg'
] ]
<BLANKLINE>
if len(sys.argv) > 1 and sys.argv[1:] != ['']:
sys.argv[:] = sys.argv[1:]
execfile(sys.argv[0])
If we change the Python version to 2.4, we'll use Python 2.4 eggs: If we change the Python version to 2.4, we'll use Python 2.4 eggs:
...@@ -139,14 +148,21 @@ If we change the Python version to 2.4, we'll use Python 2.4 eggs: ...@@ -139,14 +148,21 @@ If we change the Python version to 2.4, we'll use Python 2.4 eggs:
eggrecipedemo.main() eggrecipedemo.main()
>>> f = open(os.path.join(sample_buildout, 'bin', 'py_demo')) >>> f = open(os.path.join(sample_buildout, 'bin', 'py_demo'))
>>> f.readline().strip() == '#!' + python2_4_executable + ' -i' >>> f.readline().strip() == '#!' + python2_4_executable
True True
>>> print f.read(), >>> print f.read(),
<BLANKLINE>
import sys import sys
<BLANKLINE>
if len(sys.argv) == 1:
import os
# Restart with -i
os.execl(sys.executable, sys.executable, '-i', sys.argv[0], '')
<BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
'/tmp/tmpOBTxDMsample-buildout/eggs/demo-0.2-py2.4.egg', '/tmp/tmpiIJY3Ysample-buildout/eggs/demo-0.2-py2.4.egg',
'/tmp/tmpOBTxDMsample-buildout/eggs/demoneeded-1.1-py2.4.egg' '/tmp/tmpiIJY3Ysample-buildout/eggs/demoneeded-1.1-py2.4.egg'
] ]
<BLANKLINE>
if len(sys.argv) > 1 and sys.argv[1:] != ['']:
sys.argv[:] = sys.argv[1:]
execfile(sys.argv[0])
...@@ -309,10 +309,19 @@ def _pyscript(path, dest, executable): ...@@ -309,10 +309,19 @@ def _pyscript(path, dest, executable):
pass pass
py_script_template = '''\ py_script_template = '''\
#!%(python)s -i #!%(python)s
import sys import sys
if len(sys.argv) == 1:
import os
# Restart with -i
os.execl(sys.executable, sys.executable, '-i', sys.argv[0], '')
sys.path[0:0] = [ sys.path[0:0] = [
'%(path)s' '%(path)s'
] ]
if len(sys.argv) > 1 and sys.argv[1:] != ['']:
sys.argv[:] = sys.argv[1:]
execfile(sys.argv[0])
''' '''
...@@ -238,13 +238,24 @@ The py_demo script simply run the Python interactive interpreter with ...@@ -238,13 +238,24 @@ The py_demo script simply run the Python interactive interpreter with
the path set: the path set:
>>> cat(bin, 'py_demo') >>> cat(bin, 'py_demo')
#!/usr/local/bin/python2.3 -i #!/usr/local/bin/python2.4
<BLANKLINE>
import sys import sys
<BLANKLINE>
if len(sys.argv) == 1:
import os
# Restart with -i
os.execl(sys.executable, sys.executable, '-i', sys.argv[0], '')
<BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
'/tmp/xyzsample-install/demo-0.3-py2.3.egg', '/tmp/tmp5zS2Afsample-install/demo-0.3-py2.4.egg',
'/tmp/xyzsample-install/demoneeded-1.1-py2.3.egg' '/tmp/tmp5zS2Afsample-install/demoneeded-1.1-py2.4.egg'
] ]
<BLANKLINE>
if len(sys.argv) > 1 and sys.argv[1:] != ['']:
sys.argv[:] = sys.argv[1:]
execfile(sys.argv[0])
If invoked with a script name and arguments, it will run that script, instead.
An additional argumnet can be passed to define which scripts to install An additional argumnet can be passed to define which scripts to install
and to provie script names. The argument is a dictionary mapping and to provie script names. The argument is a dictionary mapping
......
...@@ -150,6 +150,7 @@ def test_suite(): ...@@ -150,6 +150,7 @@ def test_suite():
(re.compile('\S+sample-(\w+)'), r'/sample-\1'), (re.compile('\S+sample-(\w+)'), r'/sample-\1'),
(re.compile('executable = \S+python\S*'), (re.compile('executable = \S+python\S*'),
'executable = python'), 'executable = python'),
(re.compile('setuptools-\S+[.]egg'), 'setuptools.egg'),
]) ])
), ),
......
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