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:
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)
=====================
......
......@@ -7,7 +7,7 @@ def read(*rnames):
name = "zc.buildout"
setup(
name = name,
version = "1.0.0b11",
version = "1.0.0b12",
author = "Jim Fulton",
author_email = "jim@zope.com",
description = "System for managing development buildouts",
......
......@@ -451,6 +451,7 @@ def scripts(reqs, working_set, executable, dest,
extra_paths=(),
arguments='',
interpreter=None,
initialization='',
):
path = [dist.location for dist in working_set]
......@@ -462,6 +463,9 @@ def scripts(reqs, working_set, executable, dest,
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 @@ def scripts(reqs, working_set, executable, dest,
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 @@ def scripts(reqs, working_set, executable, dest,
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 @@ def scripts(reqs, working_set, executable, dest,
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 @@ def _script(module_name, attrs, path, dest, executable, arguments):
module_name = module_name,
attrs = attrs,
arguments = arguments,
initialization = initialization,
))
try:
os.chmod(dest, 0755)
......@@ -525,7 +533,7 @@ import sys
sys.path[0:0] = [
%(path)s,
]
%(initialization)s
import %(module_name)s
if __name__ == '__main__':
......
......@@ -59,9 +59,6 @@ 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.
......@@ -381,8 +378,8 @@ to be included in the a generated script:
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,6 +399,31 @@ parentheses in the call:
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
......
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