Commit 7c8206f2 authored by jim's avatar jim

Finished egglinker doctest.

Added the ability to control script generation.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@68520 62d5b8a3-27da-0310-9561-8e5933582275
parent b351d0a6
...@@ -92,3 +92,77 @@ the bits if the path added to reflect the eggs: ...@@ -92,3 +92,77 @@ the bits if the path added to reflect the eggs:
/tmp/tmpcy8MvGbuildout-tests/eggs/demoneeded-1.0-py2.3.egg /tmp/tmpcy8MvGbuildout-tests/eggs/demoneeded-1.0-py2.3.egg
<BLANKLINE> <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
...@@ -45,6 +45,15 @@ class Egg: ...@@ -45,6 +45,15 @@ class Egg:
always_copy = True, always_copy = True,
) )
zc.buildout.egglinker.scripts( 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], [distribution], buildout.bin, [buildout.eggs],
) scripts=scripts)
...@@ -46,17 +46,39 @@ def location(spec, eggss): ...@@ -46,17 +46,39 @@ def location(spec, eggss):
dist = env.best_match(req, pkg_resources.WorkingSet()) dist = env.best_match(req, pkg_resources.WorkingSet())
return dist.location return dist.location
def scripts(reqs, dest, eggss): def scripts(reqs, dest, eggss, scripts=None):
dists = distributions(reqs, eggss) dists = distributions(reqs, eggss)
reqs = [pkg_resources.Requirement.parse(r) for r in reqs] reqs = [pkg_resources.Requirement.parse(r) for r in reqs]
projects = [r.project_name for r in reqs] projects = [r.project_name for r in reqs]
path = "',\n '".join([dist.location for dist in dists]) path = "',\n '".join([dist.location for dist in dists])
generated = []
for dist in dists: for dist in dists:
if dist.project_name in projects: if dist.project_name in projects:
for name in pkg_resources.get_entry_map(dist, 'console_scripts'): for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
_script(dist, name, path, os.path.join(dest, name)) if scripts is not None:
_pyscript(path, os.path.join(dest, 'py_'+dist.project_name)) 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): def _script(dist, name, path, dest):
open(dest, 'w').write(script_template % dict( 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