Commit d9799304 authored by Jim Fulton's avatar Jim Fulton

Added the ability to specify initialization code when creating scripts.

parent bee2bc72
...@@ -20,6 +20,16 @@ priorities include: ...@@ -20,6 +20,16 @@ priorities include:
Change History 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) 1.0.0b11 (2006-10-24)
===================== =====================
......
...@@ -7,7 +7,7 @@ def read(*rnames): ...@@ -7,7 +7,7 @@ def read(*rnames):
name = "zc.buildout" name = "zc.buildout"
setup( setup(
name = name, name = name,
version = "1.0.0b11", version = "1.0.0b12",
author = "Jim Fulton", author = "Jim Fulton",
author_email = "jim@zope.com", author_email = "jim@zope.com",
description = "System for managing development buildouts", description = "System for managing development buildouts",
......
...@@ -451,6 +451,7 @@ def scripts(reqs, working_set, executable, dest, ...@@ -451,6 +451,7 @@ def scripts(reqs, working_set, executable, dest,
extra_paths=(), extra_paths=(),
arguments='', arguments='',
interpreter=None, interpreter=None,
initialization='',
): ):
path = [dist.location for dist in working_set] path = [dist.location for dist in working_set]
...@@ -462,6 +463,9 @@ def scripts(reqs, working_set, executable, dest, ...@@ -462,6 +463,9 @@ def scripts(reqs, working_set, executable, dest,
raise TypeError('Expected iterable of requirements or entry points,' raise TypeError('Expected iterable of requirements or entry points,'
' got string.') ' got string.')
if initialization:
initialization = '\n'+initialization+'\n'
entry_points = [] entry_points = []
for req in reqs: for req in reqs:
if isinstance(req, str): if isinstance(req, str):
...@@ -470,7 +474,8 @@ def scripts(reqs, working_set, executable, dest, ...@@ -470,7 +474,8 @@ def scripts(reqs, working_set, executable, dest,
for name in pkg_resources.get_entry_map(dist, 'console_scripts'): for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
entry_point = dist.get_entry_info('console_scripts', name) entry_point = dist.get_entry_info('console_scripts', name)
entry_points.append( entry_points.append(
(name, entry_point.module_name, '.'.join(entry_point.attrs)) (name, entry_point.module_name,
'.'.join(entry_point.attrs))
) )
else: else:
entry_points.append(req) entry_points.append(req)
...@@ -485,7 +490,8 @@ def scripts(reqs, working_set, executable, dest, ...@@ -485,7 +490,8 @@ def scripts(reqs, working_set, executable, dest,
sname = os.path.join(dest, sname) sname = os.path.join(dest, sname)
generated.extend( generated.extend(
_script(module_name, attrs, path, sname, executable, arguments) _script(module_name, attrs, path, sname, executable, arguments,
initialization)
) )
if interpreter: if interpreter:
...@@ -494,7 +500,8 @@ def scripts(reqs, working_set, executable, dest, ...@@ -494,7 +500,8 @@ def scripts(reqs, working_set, executable, dest,
return generated return generated
def _script(module_name, attrs, path, dest, executable, arguments): def _script(module_name, attrs, path, dest, executable, arguments,
initialization):
generated = [] generated = []
if sys.platform == 'win32': if sys.platform == 'win32':
# generate exe file and give the script a magic name: # generate exe file and give the script a magic name:
...@@ -510,6 +517,7 @@ def _script(module_name, attrs, path, dest, executable, arguments): ...@@ -510,6 +517,7 @@ def _script(module_name, attrs, path, dest, executable, arguments):
module_name = module_name, module_name = module_name,
attrs = attrs, attrs = attrs,
arguments = arguments, arguments = arguments,
initialization = initialization,
)) ))
try: try:
os.chmod(dest, 0755) os.chmod(dest, 0755)
...@@ -525,7 +533,7 @@ import sys ...@@ -525,7 +533,7 @@ import sys
sys.path[0:0] = [ sys.path[0:0] = [
%(path)s, %(path)s,
] ]
%(initialization)s
import %(module_name)s import %(module_name)s
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -59,9 +59,6 @@ always_unzip ...@@ -59,9 +59,6 @@ always_unzip
A flag indicating that newly-downloaded distributions should be A flag indicating that newly-downloaded distributions should be
directories even if they could be installed as zip files. 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 The install method returns a working set containing the distributions
needed to meet the given requirements. needed to meet the given requirements.
...@@ -381,8 +378,8 @@ to be included in the a generated script: ...@@ -381,8 +378,8 @@ to be included in the a generated script:
Providing script arguments Providing script arguments
-------------------------- --------------------------
A n "argument" keyword argument can be used to pass arguments to an An "argument" keyword argument can be used to pass arguments to an
entry point. The value passed source string to be placed between the entry point. The value passed is a source string to be placed between the
parentheses in the call: parentheses in the call:
>>> scripts = zc.buildout.easy_install.scripts( >>> scripts = zc.buildout.easy_install.scripts(
...@@ -402,6 +399,31 @@ parentheses in the call: ...@@ -402,6 +399,31 @@ parentheses in the call:
if __name__ == '__main__': if __name__ == '__main__':
eggrecipedemo.main(1, 2) 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 Handling custom build options for extensions
......
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