Hi Jim,
I wrote a little patch to add support for old style scripts.
I don't know if it is a good solution (maybe I missed something)
Can you please review it and help me to get it done if I misunderstood.
Many thanks,
/Mustapha
Jim Fulton wrote:
On Apr 1, 2008, at 11:07 AM, Anton Stonor wrote:
Hi there,
I was hoping a buildout guru could give a hand on this one:
The "RelStorage" package comes as an egg and installing it in a
buildout
environment works fine.
However I can't find a way to let buildout generate the zodbconvert
console script that comes with RelStorage.
easy_install RelStorage adds the script fine.
I know you should use zc.recipe.egg in this case, but no result.
The RelStorage setup.py comes with this:
scripts=['scripts/zodbconvert.py']
but no "console_scripts" entry points (maybe that is needed?)
Yes, buildout needs that. buildout only installs scripts declared as
entry points. As you discovered, you can specify the entry points
yourself. Buildout also needs the entry point to be importable from
the egg. Unfortunately, old-style distutils script handling doesn't
put the scripts in a place where they are importable.
I found a kind-of workaround:
entry-points = zodbconvert=zodbconvert:main
extra-paths =
/home/stonor/projects/mybuildout/eggs/RelStorage-1.0.1-py2.4.egg/EGG-
INFO/scripts
But it is annoying to hard code the path to
RelStorage-1.0.1-py2.4.egg/EGG-INFO/scripts.
Is there a way to dynamically look up the path to an egg with bulidout
or a another way to solve my issue?
No, because the scripts aren't included in the RelStorage Python
package and aren't in the egg path. You should get Shane to move this
script into a module that can be imported from the egg. This is what I
did with the ZODB scripts a while back.
Perhaps buildout should support the traditional script-installation
mechanism, but that mechanism assumes that the modules needed by the
script are installed into site packages and that's not a model that
buildout provides. Virtualenv supports this use case because it
emulates a Python install.
Jim
--
Jim Fulton
Zope Corporation
_______________________________________________
Distutils-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig
Index: src/zc/buildout/easy_install.py
===================================================================
--- src/zc/buildout/easy_install.py (revision 85719)
+++ src/zc/buildout/easy_install.py (working copy)
@@ -866,6 +866,18 @@
(name, entry_point.module_name,
'.'.join(entry_point.attrs))
)
+ #old style scripts if any.
+ if dist.metadata_isdir('scripts'):
+ for name in dist.metadata_listdir('scripts'):
+ sname = name
+ if scripts is not None:
+ sname = scripts.get(name)
+ if sname is None:
+ continue
+ target = os.path.join(dest, sname)
+ contents = dist.get_metadata(os.path.join('scripts' + name))
+ generated.extend(
+ _old_style_script(target, contents, path, executable))
else:
entry_points.append(req)
@@ -889,6 +901,56 @@
return generated
+def _old_style_script(dest, body, path, executable):
+ generated = []
+ script = dest
+ if sys.platform == 'win32':
+ dest += '-script.py'
+
+ body = body.strip().split('\n')
+ if body and body[0].startswith('#!/'):
+ del body[0]
+ body = '\n'.join(body)
+
+ contents = old_style_script_template % dict(
+ python = executable,
+ path = path,
+ body = body,
+ )
+
+ changed = not (os.path.exists(dest) and open(dest).read() == contents)
+
+ if sys.platform == 'win32':
+ # generate exe file and give the script a magic name:
+ exe = script+'.exe'
+ open(exe, 'wb').write(
+ pkg_resources.resource_string('setuptools', 'cli.exe')
+ )
+ generated.append(exe)
+
+ if changed:
+ open(dest, 'w').write(contents)
+ logger.info("Generated script %r.", script)
+
+ try:
+ os.chmod(dest, 0755)
+ except (AttributeError, os.error):
+ pass
+
+ generated.append(dest)
+ return generated
+
+old_style_script_template = '''\
+#!%(python)s
+
+import sys
+sys.path[0:0] = [
+ %(path)s,
+ ]
+
+%(body)s
+'''
+
def _script(module_name, attrs, path, dest, executable, arguments,
initialization):
generated = []
_______________________________________________
Distutils-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig