[Checkins] SVN: zc.buildout/trunk/ Change the script-generation logic to not use pkg_resources at run

Jim Fulton jim at zope.com
Thu Jun 8 07:32:10 EDT 2006


Log message for revision 68521:
  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.
  

Changed:
  U   zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/README.txt
  U   zc.buildout/trunk/src/zc/buildout/egglinker.py

-=-
Modified: zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/README.txt
===================================================================
--- zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/README.txt	2006-06-07 23:25:19 UTC (rev 68520)
+++ zc.buildout/trunk/eggrecipe/src/zc/recipe/egg/README.txt	2006-06-08 11:32:09 UTC (rev 68521)
@@ -82,12 +82,11 @@
 the bits if the path added to reflect the eggs:
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'py_demo'),
-    ... """for p in sys.path[:3]:
+    ... """for p in sys.path[:2]:
     ...        print p
     ... """).replace('>>> ', '').replace('... ', ''),
     ... # doctest: +ELLIPSIS
     <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/demoneeded-1.0-py2.3.egg
     <BLANKLINE>

Modified: zc.buildout/trunk/src/zc/buildout/egglinker.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/egglinker.py	2006-06-07 23:25:19 UTC (rev 68520)
+++ zc.buildout/trunk/src/zc/buildout/egglinker.py	2006-06-08 11:32:09 UTC (rev 68521)
@@ -23,6 +23,7 @@
 """
 
 # XXX needs doctest
+# XXX need to deal with extras
 
 import os
 import sys
@@ -33,7 +34,6 @@
     env = pkg_resources.Environment(eggss)
     ws = pkg_resources.WorkingSet()
     reqs = [pkg_resources.Requirement.parse(r) for r in reqs]
-    reqs.append(pkg_resources.Requirement.parse('setuptools'))
     return ws.resolve(reqs, env=env)
 
 def path(reqs, eggss):
@@ -65,7 +65,7 @@
 
                 sname = os.path.join(dest, sname)
                 generated.append(sname)
-                _script(dist, name, path, sname)
+                _script(dist, 'console_scripts', name, path, sname)
 
             name = 'py_'+dist.project_name
             if scripts is not None:
@@ -80,12 +80,15 @@
 
     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(
         python = sys.executable,
         path = path,
         project = dist.project_name,
         name = name,
+        module_name = entry_point.module_name,
+        attrs = entry_point.attrs,
         ))
     try:
         os.chmod(dest, 0755)
@@ -100,12 +103,19 @@
   '%(path)s'
   ]
 
-from pkg_resources import load_entry_point
 
-sys.exit(
-   load_entry_point('%(project)s', 'console_scripts', '%(name)s')()
-)
+module = __import__(%(module_name)r, globals(),globals(), ['__name__'])
+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()
 '''
 
 



More information about the Checkins mailing list