[Checkins] SVN: zc.buildout/branches/reinout-scripts/ old-style distutils scripts are now also detected in zipped eggs
Reinout van Rees
reinout at vanrees.org
Fri Sep 4 16:58:49 EDT 2009
Log message for revision 103557:
old-style distutils scripts are now also detected in zipped eggs
Changed:
U zc.buildout/branches/reinout-scripts/doc/tutorial.txt
U zc.buildout/branches/reinout-scripts/src/zc/buildout/downloadcache.txt
U zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py
U zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.txt
U zc.buildout/branches/reinout-scripts/src/zc/buildout/tests.py
U zc.buildout/branches/reinout-scripts/zc.recipe.egg_/src/zc/recipe/egg/README.txt
-=-
Modified: zc.buildout/branches/reinout-scripts/doc/tutorial.txt
===================================================================
--- zc.buildout/branches/reinout-scripts/doc/tutorial.txt 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/doc/tutorial.txt 2009-09-04 20:58:48 UTC (rev 103557)
@@ -863,8 +863,8 @@
If a distribution doesn't use setuptools, it may not declare it's entry
points. In that case, you can specify entry points in the recipe data.
- Buildout *does* detect distutils-style scripts without an entry point in
- case the egg is unzipped and will generate a script for them when found.
+ Buildout *does* detect distutils-style scripts without an entry point and
+ will generate a script for them when found.
Script initialization
=====================
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/downloadcache.txt
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/downloadcache.txt 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/downloadcache.txt 2009-09-04 20:58:48 UTC (rev 103557)
@@ -41,6 +41,7 @@
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
+ <a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py 2009-09-04 20:58:48 UTC (rev 103557)
@@ -33,6 +33,7 @@
import sys
import tempfile
import zc.buildout
+import zipfile
import zipimport
_oprp = getattr(os.path, 'realpath', lambda path: path)
@@ -939,18 +940,26 @@
(name, entry_point.module_name,
'.'.join(entry_point.attrs))
)
- # "old-style" distutils scripts
+ # The metadata on "old-style" distutils scripts is not retained by
+ # distutils/setuptools, except by placing the original scripts in
+ # /EGG-INFO/scripts/.
if os.path.isdir(dist.location):
- # The metadata on scripts is not retained by
- # distutils/setuptools, except by placing the original scripts
- # in /EGG-INFO/scripts/. os.listdir() is used to detect them.
- # Zipped eggs would need unpacking for this to work, which is
- # too resource intensive, so zipped eggs are not supported.
+ # Unzipped egg: use os.listdir() to detect possible scripts.
scripts_dir = os.path.join(dist.location, 'EGG-INFO', 'scripts')
if os.path.exists(scripts_dir):
for name in os.listdir(scripts_dir):
distutils_scripts.append(
(name, os.path.join(scripts_dir, name)))
+ else:
+ # Zipped egg: use zipfile to detect possible scripts.
+ zipped = zipfile.ZipFile(dist.location)
+ for filepath in zipped.namelist():
+ if filepath.startswith('EGG-INFO/scripts'):
+ name = os.path.basename(filepath)
+ fd, tmp_script = tempfile.mkstemp()
+ os.write(fd, zipped.read(filepath))
+ os.close(fd)
+ distutils_scripts.append((name, tmp_script))
else:
entry_points.append(req)
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.txt 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.txt 2009-09-04 20:58:48 UTC (rev 103557)
@@ -109,6 +109,7 @@
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
+ <a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
@@ -929,6 +930,18 @@
>>> ls(distbin)
- distutilsscript
+It also works for zipped eggs:
+
+ >>> distdir2 = tmpdir('distutilsscriptdir2')
+ >>> distbin2 = tmpdir('distutilsscriptbin2')
+ >>> ws = zc.buildout.easy_install.install(
+ ... ['du_zipped'], distdir2,
+ ... links=[link_server], index=link_server+'index/')
+ >>> scripts = zc.buildout.easy_install.scripts(
+ ... ['du_zipped'], ws, sys.executable, distbin2)
+ >>> ls(distbin2)
+ - distutilsscript
+
Distutils copies the script files verbatim, apart from a line at the top that
looks like ``#!/usr/bin/python``, which gets replaced by the actual python
interpreter. Buildout does the same, but additionally also adds the sys.path
@@ -948,9 +961,6 @@
Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to.
-A second restriction is that scripts are only detected if the eggs are
-unzipped. Unzipping all zipped eggs for detecting old-style distutils scripts
-is a bit wasteful.
Handling custom build options for extensions provided in source distributions
-----------------------------------------------------------------------------
@@ -1075,6 +1085,7 @@
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
+ <a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br>
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/tests.py 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/tests.py 2009-09-04 20:58:48 UTC (rev 103557)
@@ -2685,6 +2685,15 @@
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
+ write(
+ tmp, 'setup.py',
+ "from setuptools import setup\n"
+ "setup(name='du_zipped', zip_safe=True, version='1.0', "
+ "scripts=['distutilsscript'],"
+ "py_modules=['eggrecipedemoneeded'])\n"
+ )
+ zc.buildout.testing.bdist_egg(tmp, executable, dest)
+
os.remove(os.path.join(tmp, 'distutilsscript'))
os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
Modified: zc.buildout/branches/reinout-scripts/zc.recipe.egg_/src/zc/recipe/egg/README.txt
===================================================================
--- zc.buildout/branches/reinout-scripts/zc.recipe.egg_/src/zc/recipe/egg/README.txt 2009-09-04 19:16:15 UTC (rev 103556)
+++ zc.buildout/branches/reinout-scripts/zc.recipe.egg_/src/zc/recipe/egg/README.txt 2009-09-04 20:58:48 UTC (rev 103557)
@@ -41,6 +41,7 @@
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
+ <a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.3.egg">other-1.0-py2.3.egg</a><br>
More information about the checkins
mailing list