Commit e9c3b06b authored by Jim Fulton's avatar Jim Fulton

Change the script-generation logic to not use pkg_resources at run

time. Rather, we generate in-line logic that pkg_resources would provide.
This means that apps that don't actually use pkg_resources themselves
don't end up running it and we don't need to implicitly include the
setuptools egg in the script path.  Of course, if an application does
use setuptools, then setuptools will be one of it's requirements and
will be included in the path.
parent f1c87887
...@@ -82,12 +82,11 @@ We can also run the py_demo script. Here we'll just print out ...@@ -82,12 +82,11 @@ We can also run the py_demo script. Here we'll just print out
the bits if the path added to reflect the eggs: the bits if the path added to reflect the eggs:
>>> print system(os.path.join(sample_buildout, 'bin', 'py_demo'), >>> print system(os.path.join(sample_buildout, 'bin', 'py_demo'),
... """for p in sys.path[:3]: ... """for p in sys.path[:2]:
... print p ... print p
... """).replace('>>> ', '').replace('... ', ''), ... """).replace('>>> ', '').replace('... ', ''),
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
<BLANKLINE> <BLANKLINE>
/usr/local/python/2.3.5/lib/python/setuptools-0.6b2-py2.3.egg
/tmp/tmpcy8MvGbuildout-tests/eggs/demo-0.2-py2.3.egg /tmp/tmpcy8MvGbuildout-tests/eggs/demo-0.2-py2.3.egg
/tmp/tmpcy8MvGbuildout-tests/eggs/demoneeded-1.0-py2.3.egg /tmp/tmpcy8MvGbuildout-tests/eggs/demoneeded-1.0-py2.3.egg
<BLANKLINE> <BLANKLINE>
......
...@@ -23,6 +23,7 @@ $Id$ ...@@ -23,6 +23,7 @@ $Id$
""" """
# XXX needs doctest # XXX needs doctest
# XXX need to deal with extras
import os import os
import sys import sys
...@@ -33,7 +34,6 @@ def distributions(reqs, eggss): ...@@ -33,7 +34,6 @@ def distributions(reqs, eggss):
env = pkg_resources.Environment(eggss) env = pkg_resources.Environment(eggss)
ws = pkg_resources.WorkingSet() ws = pkg_resources.WorkingSet()
reqs = [pkg_resources.Requirement.parse(r) for r in reqs] reqs = [pkg_resources.Requirement.parse(r) for r in reqs]
reqs.append(pkg_resources.Requirement.parse('setuptools'))
return ws.resolve(reqs, env=env) return ws.resolve(reqs, env=env)
def path(reqs, eggss): def path(reqs, eggss):
...@@ -65,7 +65,7 @@ def scripts(reqs, dest, eggss, scripts=None): ...@@ -65,7 +65,7 @@ def scripts(reqs, dest, eggss, scripts=None):
sname = os.path.join(dest, sname) sname = os.path.join(dest, sname)
generated.append(sname) generated.append(sname)
_script(dist, name, path, sname) _script(dist, 'console_scripts', name, path, sname)
name = 'py_'+dist.project_name name = 'py_'+dist.project_name
if scripts is not None: if scripts is not None:
...@@ -80,12 +80,15 @@ def scripts(reqs, dest, eggss, scripts=None): ...@@ -80,12 +80,15 @@ def scripts(reqs, dest, eggss, scripts=None):
return generated return generated
def _script(dist, name, path, dest): def _script(dist, group, name, path, dest):
entry_point = dist.get_entry_info(group, name)
open(dest, 'w').write(script_template % dict( open(dest, 'w').write(script_template % dict(
python = sys.executable, python = sys.executable,
path = path, path = path,
project = dist.project_name, project = dist.project_name,
name = name, name = name,
module_name = entry_point.module_name,
attrs = entry_point.attrs,
)) ))
try: try:
os.chmod(dest, 0755) os.chmod(dest, 0755)
...@@ -100,12 +103,19 @@ sys.path[0:0] = [ ...@@ -100,12 +103,19 @@ sys.path[0:0] = [
'%(path)s' '%(path)s'
] ]
from pkg_resources import load_entry_point
sys.exit( module = __import__(%(module_name)r, globals(),globals(), ['__name__'])
load_entry_point('%(project)s', 'console_scripts', '%(name)s')() attrs = %(attrs)r
)
entry = module
for attr in attrs:
try:
entry = getattr(entry, attr)
except AttributeError:
raise ImportError("%%r has no %%r attribute" %% (module, attrs))
if __name__ == '__main__':
entry()
''' '''
......
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