Commit 2495c2b8 authored by Jim Fulton's avatar Jim Fulton

Added an extra-paths option to specify extra paths to be inclided in

generated script paths.

Added an arguments option to specify source for arguments to be passed
to entry points.
parent b6aae481
......@@ -324,11 +324,16 @@ def build(spec, dest, build_ext,
def working_set(specs, executable, path):
return install(specs, None, executable=executable, path=path)
def scripts(reqs, working_set, executable, dest, scripts=None):
def scripts(reqs, working_set, executable, dest,
scripts=None,
extra_paths=(),
arguments='',
):
reqs = [pkg_resources.Requirement.parse(r) for r in reqs]
projects = [r.project_name for r in reqs]
path = repr([dist.location for dist in working_set])
path = path[1:-1].replace(',', ',\n ')
path = [dist.location for dist in working_set]
path.extend(extra_paths)
path = repr(path)[1:-1].replace(',', ',\n ')
generated = []
for dist in working_set:
......@@ -344,7 +349,7 @@ def scripts(reqs, working_set, executable, dest, scripts=None):
sname = os.path.join(dest, sname)
generated.extend(
_script(dist, 'console_scripts', name, path, sname,
executable)
executable, arguments)
)
name = 'py-'+dist.project_name
......@@ -361,7 +366,7 @@ def scripts(reqs, working_set, executable, dest, scripts=None):
return generated
def _script(dist, group, name, path, dest, executable):
def _script(dist, group, name, path, dest, executable, arguments):
entry_point = dist.get_entry_info(group, name)
generated = []
if sys.platform == 'win32':
......@@ -379,6 +384,7 @@ def _script(dist, group, name, path, dest, executable):
name = name,
module_name = entry_point.module_name,
attrs = '.'.join(entry_point.attrs),
arguments = arguments,
))
try:
os.chmod(dest, 0755)
......@@ -398,7 +404,7 @@ sys.path[0:0] = [
import %(module_name)s
if __name__ == '__main__':
%(module_name)s.%(attrs)s()
%(module_name)s.%(attrs)s(%(arguments)s)
'''
......
......@@ -59,6 +59,9 @@ always_unzip
A flag indicating that newly-downloaded distributions should be
directories even if they could be installed as zip files.
arguments
Source code to be used to pass arguments when calling a script entry point.
The install method returns a working set containing the distributions
needed to meet the given requirements.
......@@ -220,11 +223,7 @@ The return value is a list of the scripts generated:
The demo script run the entry point defined in the demo egg:
>>> if sys.platform == 'win32':
... cat(bin, 'demo-script.py')
... else:
... cat(bin, 'demo')
... # doctest: +NORMALIZE_WHITESPACE
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.3
<BLANKLINE>
import sys
......@@ -248,11 +247,7 @@ Some things to note:
The py-demo script simply run the Python interactive interpreter with
the path set:
>>> if sys.platform == 'win32':
... cat(bin, 'py-demo-script.py')
... else:
... cat(bin, 'py-demo')
... # doctest: +NORMALIZE_WHITESPACE
>>> cat(bin, 'py-demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
import sys
<BLANKLINE>
......@@ -302,6 +297,57 @@ original script names to new script names.
>>> print system(os.path.join(bin, 'run')),
3 1
Including extra paths in scripts
--------------------------------
We can pass a keyword argument, extra paths, to caue additional paths
to be included in the a generated script:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo==0.1'], ws, python2_4_executable, bin, dict(demo='run'),
... extra_paths=['/foo/bar'])
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.3
<BLANKLINE>
import sys
sys.path[0:0] = [
'/tmp/xyzsample-install/demo-0.3-py2.3.egg',
'/tmp/xyzsample-install/demoneeded-1.1-py2.3.egg',
'/foo/bar'
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
eggrecipedemo.main()
Providing script arguments
--------------------------
A n "argument" keyword argument can be used to pass arguments to an
entry point. The value passed source string to be placed between the
parentheses in the call:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo==0.1'], ws, python2_4_executable, bin, dict(demo='run'),
... arguments='1, 2')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.3
import sys
sys.path[0:0] = [
'/tmp/xyzsample-install/demo-0.3-py2.3.egg',
'/tmp/xyzsample-install/demoneeded-1.1-py2.3.egg'
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
eggrecipedemo.main(1, 2)
Handling custom build options for extensions
--------------------------------------------
......
......@@ -27,6 +27,11 @@ import zc.buildout.buildout
def cat(dir, *names):
path = os.path.join(dir, *names)
if (not os.path.exists(path)
and sys.platform == 'win32'
and os.path.exists(path+'-script.py')
):
path = path+'-script.py'
print open(path).read(),
def ls(dir, *subs):
......
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