[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/ Added an
extra-paths option to specify extra paths to be inclided in
Jim Fulton
jim at zope.com
Tue Aug 29 13:11:17 EDT 2006
Log message for revision 69864:
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.
Changed:
U zc.buildout/trunk/src/zc/buildout/easy_install.py
U zc.buildout/trunk/src/zc/buildout/easy_install.txt
U zc.buildout/trunk/src/zc/buildout/testing.py
-=-
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.py 2006-08-29 17:11:13 UTC (rev 69863)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.py 2006-08-29 17:11:15 UTC (rev 69864)
@@ -324,11 +324,16 @@
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 @@
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 @@
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 @@
name = name,
module_name = entry_point.module_name,
attrs = '.'.join(entry_point.attrs),
+ arguments = arguments,
))
try:
os.chmod(dest, 0755)
@@ -398,7 +404,7 @@
import %(module_name)s
if __name__ == '__main__':
- %(module_name)s.%(attrs)s()
+ %(module_name)s.%(attrs)s(%(arguments)s)
'''
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-08-29 17:11:13 UTC (rev 69863)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-08-29 17:11:15 UTC (rev 69864)
@@ -59,6 +59,9 @@
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 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 @@
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 @@
>>> 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
--------------------------------------------
Modified: zc.buildout/trunk/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/testing.py 2006-08-29 17:11:13 UTC (rev 69863)
+++ zc.buildout/trunk/src/zc/buildout/testing.py 2006-08-29 17:11:15 UTC (rev 69864)
@@ -27,6 +27,11 @@
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):
More information about the Checkins
mailing list