Commit 8a3f1e9f authored by Jim Fulton's avatar Jim Fulton

Merge remote branch 'remotes/origin/reinout-scripts'

Providing support for non-entry-point-based scripts.
parents 89feb749 6c71c546
Change History Change History
************** **************
1.4.5 (unreleased) ?.?.? (unreleased)
================== ==================
- Distutils-style scripts are also installed now (for instance pyflakes' and
docutils' scripts). https://bugs.launchpad.net/zc.buildout/+bug/422724
- Switched development location to github.com/buildout. - Switched development location to github.com/buildout.
- Avoid sorting the working set and requirements when it won't be - Avoid sorting the working set and requirements when it won't be
......
...@@ -861,9 +861,10 @@ Installing scripts ...@@ -861,9 +861,10 @@ Installing scripts
If any of the named eggs have ``console_script`` entry If any of the named eggs have ``console_script`` entry
points, then scripts will be generated for the entry points. points, then scripts will be generated for the entry points.
If a distribution doesn't use setuptools, it may not declare it's If a distribution doesn't use setuptools, it may not declare it's entry
entry points. In that case, you can specify entry points in the points. In that case, you can specify entry points in the recipe data.
recipe data. Buildout *does* detect distutils-style scripts without an entry point and
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>
......
...@@ -863,16 +863,25 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -863,16 +863,25 @@ def scripts(reqs, working_set, executable, dest=None,
initialization = '\n'+initialization+'\n' initialization = '\n'+initialization+'\n'
entry_points = [] entry_points = []
distutils_scripts = []
for req in reqs: for req in reqs:
if isinstance(req, str): if isinstance(req, str):
req = pkg_resources.Requirement.parse(req) req = pkg_resources.Requirement.parse(req)
dist = working_set.find(req) dist = working_set.find(req)
# regular console_scripts entry points
for name in pkg_resources.get_entry_map(dist, 'console_scripts'): for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
entry_point = dist.get_entry_info('console_scripts', name) entry_point = dist.get_entry_info('console_scripts', name)
entry_points.append( entry_points.append(
(name, entry_point.module_name, (name, entry_point.module_name,
'.'.join(entry_point.attrs)) '.'.join(entry_point.attrs))
) )
# The metadata on "old-style" distutils scripts is not retained by
# distutils/setuptools, except by placing the original scripts in
# /EGG-INFO/scripts/.
if dist.metadata_isdir('scripts'):
for name in dist.metadata_listdir('scripts'):
contents = dist.get_metadata('scripts/' + name)
distutils_scripts.append((name, contents))
else: else:
entry_points.append(req) entry_points.append(req)
...@@ -892,6 +901,22 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -892,6 +901,22 @@ def scripts(reqs, working_set, executable, dest=None,
initialization, rpsetup) initialization, rpsetup)
) )
for name, contents in distutils_scripts:
if scripts is not None:
sname = scripts.get(name)
if sname is None:
continue
else:
sname = name
sname = os.path.join(dest, sname)
spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
generated.extend(
_distutils_script(spath, sname, contents,
executable, initialization, rpsetup)
)
if interpreter: if interpreter:
sname = os.path.join(dest, interpreter) sname = os.path.join(dest, interpreter)
spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths) spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
...@@ -899,6 +924,7 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -899,6 +924,7 @@ def scripts(reqs, working_set, executable, dest=None,
return generated return generated
def _relative_path_and_setup(sname, path, relative_paths): def _relative_path_and_setup(sname, path, relative_paths):
if relative_paths: if relative_paths:
relative_paths = os.path.normcase(relative_paths) relative_paths = os.path.normcase(relative_paths)
...@@ -928,6 +954,7 @@ def _relative_depth(common, path): ...@@ -928,6 +954,7 @@ def _relative_depth(common, path):
path = dirname path = dirname
return n return n
def _relative_path(common, path): def _relative_path(common, path):
r = [] r = []
while 1: while 1:
...@@ -941,6 +968,7 @@ def _relative_path(common, path): ...@@ -941,6 +968,7 @@ def _relative_path(common, path):
r.reverse() r.reverse()
return os.path.join(*r) return os.path.join(*r)
def _relativitize(path, script, relative_paths): def _relativitize(path, script, relative_paths):
if path == script: if path == script:
raise AssertionError("path == script") raise AssertionError("path == script")
...@@ -975,6 +1003,33 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup): ...@@ -975,6 +1003,33 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup):
initialization = initialization, initialization = initialization,
relative_paths_setup = rsetup, relative_paths_setup = rsetup,
) )
return _create_script(contents, dest)
def _distutils_script(path, dest, script_content, executable,
initialization, rsetup):
lines = script_content.splitlines(True)
if not ('#!' in lines[0]) and ('python' in lines[0]):
# The script doesn't follow distutil's rules. Ignore it.
return []
original_content = ''.join(lines[1:])
contents = distutils_script_template % dict(
python = _safe_arg(executable),
path = path,
initialization = initialization,
relative_paths_setup = rsetup,
original_content = original_content
)
return _create_script(contents, dest)
def _create_script(contents, dest):
generated = []
script = dest
if is_win32:
dest += '-script.py'
changed = not (os.path.exists(dest) and open(dest).read() == contents) changed = not (os.path.exists(dest) and open(dest).read() == contents)
if is_win32: if is_win32:
...@@ -998,6 +1053,7 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup): ...@@ -998,6 +1053,7 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup):
generated.append(dest) generated.append(dest)
return generated return generated
if is_jython and jython_os_name == 'linux': if is_jython and jython_os_name == 'linux':
script_header = '#!/usr/bin/env %(python)s' script_header = '#!/usr/bin/env %(python)s'
else: else:
...@@ -1018,6 +1074,18 @@ if __name__ == '__main__': ...@@ -1018,6 +1074,18 @@ if __name__ == '__main__':
%(module_name)s.%(attrs)s(%(arguments)s) %(module_name)s.%(attrs)s(%(arguments)s)
''' '''
distutils_script_template = script_header + '''\
%(relative_paths_setup)s
import sys
sys.path[0:0] = [
%(path)s,
]
%(initialization)s
%(original_content)s
'''
def _pyscript(path, dest, rsetup): def _pyscript(path, dest, rsetup):
generated = [] generated = []
......
...@@ -101,6 +101,7 @@ We have a link server that has a number of eggs: ...@@ -101,6 +101,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>
...@@ -865,6 +866,55 @@ We specified an interpreter and its paths are adjusted too: ...@@ -865,6 +866,55 @@ We specified an interpreter and its paths are adjusted too:
__import__("code").interact(banner="", local=globals()) __import__("code").interact(banner="", local=globals())
Installing distutils-style scripts
----------------------------------
Most python libraries use the console_scripts entry point nowadays. But
several still have a ``scripts=['bin/something']`` in their setup() call.
Buildout also installs those:
>>> distdir = tmpdir('distutilsscriptdir')
>>> distbin = tmpdir('distutilsscriptbin')
>>> ws = zc.buildout.easy_install.install(
... ['other'], distdir,
... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['other'], ws, sys.executable, distbin)
>>> 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
like for the console_scripts:
>>> cat(distbin, 'distutilsscript')
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/distutilsscriptdir/other-1.0-pyN.N.egg',
]
<BLANKLINE>
<BLANKLINE>
print "distutils!"
Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to.
Handling custom build options for extensions provided in source distributions Handling custom build options for extensions provided in source distributions
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
...@@ -984,6 +1034,7 @@ Let's update our link server with a new version of extdemo: ...@@ -984,6 +1034,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>
......
...@@ -2624,14 +2624,26 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2624,14 +2624,26 @@ def create_sample_eggs(test, executable=sys.executable):
) )
zc.buildout.testing.sdist(tmp, dest) zc.buildout.testing.sdist(tmp, dest)
write(tmp, 'distutilsscript', '#!/usr/bin/python\nprint "distutils!"')
write( write(
tmp, 'setup.py', tmp, 'setup.py',
"from setuptools import setup\n" "from setuptools import setup\n"
"setup(name='other', zip_safe=False, version='1.0', " "setup(name='other', zip_safe=False, version='1.0', "
"scripts=['distutilsscript'],"
"py_modules=['eggrecipedemoneeded'])\n" "py_modules=['eggrecipedemoneeded'])\n"
) )
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest) zc.buildout.testing.bdist_egg(tmp, sys.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')) os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
for i in (1, 2, 3, 4): for i in (1, 2, 3, 4):
......
...@@ -35,6 +35,7 @@ We have a link server that has a number of distributions: ...@@ -35,6 +35,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