Commit 3ee1ab2c authored by Reinout van Rees's avatar Reinout van Rees

old-style distutils scripts are now also detected in zipped eggs

parent 1ba552fa
...@@ -863,8 +863,8 @@ Installing scripts ...@@ -863,8 +863,8 @@ Installing scripts
If a distribution doesn't use setuptools, it may not declare it's entry 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. points. In that case, you can specify entry points in the recipe data.
Buildout *does* detect distutils-style scripts without an entry point in Buildout *does* detect distutils-style scripts without an entry point and
case the egg is unzipped and will generate a script for them when found. will generate a script for them when found.
Script initialization Script initialization
===================== =====================
......
...@@ -41,6 +41,7 @@ download: ...@@ -41,6 +41,7 @@ download:
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br> <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.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.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.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br> <a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br> <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
......
...@@ -33,6 +33,7 @@ import subprocess ...@@ -33,6 +33,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import zc.buildout import zc.buildout
import zipfile
import zipimport import zipimport
_oprp = getattr(os.path, 'realpath', lambda path: path) _oprp = getattr(os.path, 'realpath', lambda path: path)
...@@ -939,18 +940,26 @@ def scripts(reqs, working_set, executable, dest, ...@@ -939,18 +940,26 @@ def scripts(reqs, working_set, executable, dest,
(name, entry_point.module_name, (name, entry_point.module_name,
'.'.join(entry_point.attrs)) '.'.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): if os.path.isdir(dist.location):
# The metadata on scripts is not retained by # Unzipped egg: use os.listdir() to detect possible scripts.
# 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.
scripts_dir = os.path.join(dist.location, 'EGG-INFO', 'scripts') scripts_dir = os.path.join(dist.location, 'EGG-INFO', 'scripts')
if os.path.exists(scripts_dir): if os.path.exists(scripts_dir):
for name in os.listdir(scripts_dir): for name in os.listdir(scripts_dir):
distutils_scripts.append( distutils_scripts.append(
(name, os.path.join(scripts_dir, name))) (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: else:
entry_points.append(req) entry_points.append(req)
......
...@@ -109,6 +109,7 @@ We have a link server that has a number of eggs: ...@@ -109,6 +109,7 @@ We have a link server that has a number of eggs:
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br> <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.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.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.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br> <a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br> <a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
...@@ -929,6 +930,18 @@ Buildout also installs those: ...@@ -929,6 +930,18 @@ Buildout also installs those:
>>> ls(distbin) >>> ls(distbin)
- distutilsscript - 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 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 looks like ``#!/usr/bin/python``, which gets replaced by the actual python
interpreter. Buildout does the same, but additionally also adds the sys.path interpreter. Buildout does the same, but additionally also adds the sys.path
...@@ -948,9 +961,6 @@ like for the console_scripts: ...@@ -948,9 +961,6 @@ like for the console_scripts:
Due to the nature of distutils scripts, buildout cannot pass arguments as Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to. 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 Handling custom build options for extensions provided in source distributions
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
...@@ -1075,6 +1085,7 @@ Let's update our link server with a new version of extdemo: ...@@ -1075,6 +1085,7 @@ Let's update our link server with a new version of extdemo:
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br> <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.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.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.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br> <a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br> <a href="index/">index/</a><br>
......
...@@ -2685,6 +2685,15 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2685,6 +2685,15 @@ def create_sample_eggs(test, executable=sys.executable):
) )
zc.buildout.testing.bdist_egg(tmp, executable, dest) 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, 'distutilsscript'))
os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py')) os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
......
...@@ -41,6 +41,7 @@ We have a link server that has a number of distributions: ...@@ -41,6 +41,7 @@ We have a link server that has a number of distributions:
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br> <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.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.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.4.zip">extdemo-1.4.zip</a><br>
<a href="index/">index/</a><br> <a href="index/">index/</a><br>
<a href="other-1.0-py2.3.egg">other-1.0-py2.3.egg</a><br> <a href="other-1.0-py2.3.egg">other-1.0-py2.3.egg</a><br>
......
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