[Checkins] SVN: zc.buildout/trunk/ Added the ability to specify
initialization code when creating scripts.
Jim Fulton
jim at zope.com
Tue Oct 24 19:30:25 EDT 2006
Log message for revision 70903:
Added the ability to specify initialization code when creating scripts.
Changed:
U zc.buildout/trunk/CHANGES.txt
U zc.buildout/trunk/setup.py
U zc.buildout/trunk/src/zc/buildout/easy_install.py
U zc.buildout/trunk/src/zc/buildout/easy_install.txt
-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt 2006-10-24 21:05:16 UTC (rev 70902)
+++ zc.buildout/trunk/CHANGES.txt 2006-10-24 23:30:24 UTC (rev 70903)
@@ -20,6 +20,16 @@
Change History
**************
+1.0.0b12 (2006-10-24)
+=====================
+
+Feature Changes
+---------------
+
+- Added an initialization argument to the
+ zc.buildout.easy_install.scripts function to include initialization
+ code in generated scripts.
+
1.0.0b11 (2006-10-24)
=====================
Modified: zc.buildout/trunk/setup.py
===================================================================
--- zc.buildout/trunk/setup.py 2006-10-24 21:05:16 UTC (rev 70902)
+++ zc.buildout/trunk/setup.py 2006-10-24 23:30:24 UTC (rev 70903)
@@ -7,7 +7,7 @@
name = "zc.buildout"
setup(
name = name,
- version = "1.0.0b11",
+ version = "1.0.0b12",
author = "Jim Fulton",
author_email = "jim at zope.com",
description = "System for managing development buildouts",
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.py 2006-10-24 21:05:16 UTC (rev 70902)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.py 2006-10-24 23:30:24 UTC (rev 70903)
@@ -451,6 +451,7 @@
extra_paths=(),
arguments='',
interpreter=None,
+ initialization='',
):
path = [dist.location for dist in working_set]
@@ -462,6 +463,9 @@
raise TypeError('Expected iterable of requirements or entry points,'
' got string.')
+ if initialization:
+ initialization = '\n'+initialization+'\n'
+
entry_points = []
for req in reqs:
if isinstance(req, str):
@@ -470,7 +474,8 @@
for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
entry_point = dist.get_entry_info('console_scripts', name)
entry_points.append(
- (name, entry_point.module_name, '.'.join(entry_point.attrs))
+ (name, entry_point.module_name,
+ '.'.join(entry_point.attrs))
)
else:
entry_points.append(req)
@@ -485,7 +490,8 @@
sname = os.path.join(dest, sname)
generated.extend(
- _script(module_name, attrs, path, sname, executable, arguments)
+ _script(module_name, attrs, path, sname, executable, arguments,
+ initialization)
)
if interpreter:
@@ -494,7 +500,8 @@
return generated
-def _script(module_name, attrs, path, dest, executable, arguments):
+def _script(module_name, attrs, path, dest, executable, arguments,
+ initialization):
generated = []
if sys.platform == 'win32':
# generate exe file and give the script a magic name:
@@ -510,6 +517,7 @@
module_name = module_name,
attrs = attrs,
arguments = arguments,
+ initialization = initialization,
))
try:
os.chmod(dest, 0755)
@@ -525,7 +533,7 @@
sys.path[0:0] = [
%(path)s,
]
-
+%(initialization)s
import %(module_name)s
if __name__ == '__main__':
Modified: zc.buildout/trunk/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-10-24 21:05:16 UTC (rev 70902)
+++ zc.buildout/trunk/src/zc/buildout/easy_install.txt 2006-10-24 23:30:24 UTC (rev 70903)
@@ -59,9 +59,6 @@
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.
@@ -381,8 +378,8 @@
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
+An "argument" keyword argument can be used to pass arguments to an
+entry point. The value passed is a source string to be placed between the
parentheses in the call:
>>> scripts = zc.buildout.easy_install.scripts(
@@ -402,8 +399,33 @@
if __name__ == '__main__':
eggrecipedemo.main(1, 2)
+Passing initialization code
+---------------------------
+You can also pass script initialization code:
+ >>> scripts = zc.buildout.easy_install.scripts(
+ ... ['demo'], ws, sys.executable, bin, dict(demo='run'),
+ ... arguments='1, 2',
+ ... initialization='import os\nos.chdir("foo")')
+
+ >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
+ #!/usr/local/bin/python2.4
+ import sys
+ sys.path[0:0] = [
+ '/sample-install/demo-0.3-py2.4.egg',
+ '/sample-install/demoneeded-1.1-py2.4.egg',
+ ]
+ <BLANKLINE>
+ import os
+ os.chdir("foo")
+ <BLANKLINE>
+ import eggrecipedemo
+ <BLANKLINE>
+ if __name__ == '__main__':
+ eggrecipedemo.main(1, 2)
+
+
Handling custom build options for extensions
--------------------------------------------
More information about the Checkins
mailing list