Commit f1c87887 authored by Jim Fulton's avatar Jim Fulton

Finished egglinker doctest.

Added the ability to control script generation.
parent 4215b4b7
......@@ -92,3 +92,77 @@ the bits if the path added to reflect the eggs:
/tmp/tmpcy8MvGbuildout-tests/eggs/demoneeded-1.0-py2.3.egg
<BLANKLINE>
The recipe gets the most recent distribution that satisfies the
specification. For example, if we remove the restriction on demo:
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo
...
... [demo]
... recipe = zc.recipe.egg
... distribution = demo
... find_links = %s
... """ % sample_eggs)
and rerun the buildout:
>>> print system(runscript),
Then we'll get a new demo egg:
>>> ls(sample_buildout, 'eggs')
- demo-0.2-py2.3.egg
- demo-0.3-py2.3.egg
- demoneeded-1.0-py2.3.egg
- zc.recipe.egg.egg-link
The script is updated too:
>>> print system(os.path.join(sample_buildout, 'bin', 'demo')),
3 1
You can control which scripts get generated using the scripts option.
For example, to suppress scripts, use the scripts option without any
arguments:
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo
...
... [demo]
... recipe = zc.recipe.egg
... distribution = demo
... find_links = %s
... scripts =
... """ % sample_eggs)
>>> print system(runscript),
>>> ls(sample_buildout, 'bin')
- buildout
You can also control the name used for scripts:
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo
...
... [demo]
... recipe = zc.recipe.egg
... distribution = demo
... find_links = %s
... scripts = demo=foo
... """ % sample_eggs)
>>> print system(runscript),
>>> ls(sample_buildout, 'bin')
- buildout
- foo
......@@ -44,7 +44,16 @@ class Egg:
[buildout.buildout_path(link) for link in links],
always_copy = True,
)
zc.buildout.egglinker.scripts(
[distribution], buildout.bin, [buildout.eggs],
)
scripts = self.options.get('scripts')
if scripts or scripts is None:
if scripts is not None:
scripts = scripts.split()
scripts = dict([
('=' in s) and s.split('=', 1) or (s, s)
for s in scripts
])
return zc.buildout.egglinker.scripts(
[distribution], buildout.bin, [buildout.eggs],
scripts=scripts)
......@@ -46,17 +46,39 @@ def location(spec, eggss):
dist = env.best_match(req, pkg_resources.WorkingSet())
return dist.location
def scripts(reqs, dest, eggss):
def scripts(reqs, dest, eggss, scripts=None):
dists = distributions(reqs, eggss)
reqs = [pkg_resources.Requirement.parse(r) for r in reqs]
projects = [r.project_name for r in reqs]
path = "',\n '".join([dist.location for dist in dists])
generated = []
for dist in dists:
if dist.project_name in projects:
for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
_script(dist, name, path, os.path.join(dest, name))
_pyscript(path, os.path.join(dest, 'py_'+dist.project_name))
if scripts is not None:
sname = scripts.get(name)
if sname is None:
continue
else:
sname = name
sname = os.path.join(dest, sname)
generated.append(sname)
_script(dist, name, path, sname)
name = 'py_'+dist.project_name
if scripts is not None:
sname = scripts.get(name)
else:
sname = name
if sname is not None:
sname = os.path.join(dest, sname)
generated.append(sname)
_pyscript(path, sname)
return generated
def _script(dist, name, path, dest):
open(dest, 'w').write(script_template % dict(
......
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