zc.buildout and zc.recipe.egg

Hi, Apologies for the length of this post. I am using zc.buildout to compile a specific python version with various extra libraries (e.g. aspell, mysql). This is all working fine, and I have it creating an interpreter with all the required libraries via the "interpreter" parameter. However, I then want to compile/make/make install zope2 against this specific python interpreter via ./configure --with-python=./bin/mypython etc... I am using the zc.recipe.cmmi recipe to do this. This fails (it works if I use the python executable as the --with-python argument). I've tracked it down to a small difference between the standard python interpreter and the one generated by the zc.recipe.egg recipe: - the standard python interpreter seems to add the directory of the file you are running to the path - the generated one does not add the directory to the path This means that ./Python2.3/bin/python inst/configure.py runs fine but ./bin/mypython inst/configure.py fails with an import error as it cannot import anything relative to the file being run I don't want to add it in as an "extra_path" because it is not needed after this step and I don't want it to be part of the standard environment. My question is: - is this a desirable difference in behaviour between the two interpreters? I expected them to work exactly the same... - what's the cleanest way to get this working consistently/in an automated way through the buildout? At the moment, I have manually added the following into the generated script to recreate the behaviour: if _args: + import os + sys.argv[:] = _args + f = sys.argv[0] + p = os.path.split( os.path.abspath(f) )[:-1] + sys.path[0:0] = os.path.join( p ) execfile(f) Thanks, Miles

On Monday 16 July 2007, Miles wrote:
- the standard python interpreter seems to add the directory of the file you are running to the path - the generated one does not add the directory to the path
That's correct. This is a limitation in zc.recipe.egg; we're open to patches that improve the generated interpreter script. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org>

Hi,
That's correct. This is a limitation in zc.recipe.egg; we're open to patches that improve the generated interpreter script.
Thanks for confirming, I wasn't sure if it was like that for a reason. I attach a patch that fixes up some other parameters so the generated interpreter script's behaviour is less distinguis matches what you get when you start the python interpreter more exactly. Works for me, but I'd appreciate some more eyes... Miles

Much thanks. Can you also supply a test? Better yet, since you are a zope contributor, you could just check in the change, including the test. Jim On Jul 19, 2007, at 5:21 PM, Miles wrote:
Hi,
That's correct. This is a limitation in zc.recipe.egg; we're open to patches that improve the generated interpreter script.
Thanks for confirming, I wasn't sure if it was like that for a reason.
I attach a patch that fixes up some other parameters so the generated interpreter script's behaviour is less distinguis matches what you get when you start the python interpreter more exactly. Works for me, but I'd appreciate some more eyes...
Miles
Index: zc.buildout/src/zc/buildout/easy_install.py =================================================================== --- zc.buildout/src/zc/buildout/easy_install.py (revision 78190) +++ zc.buildout/src/zc/buildout/easy_install.py (working copy) @@ -896,11 +896,17 @@ py_script_template = '''\ #!%(python)s import sys - +import os + sys.path[0:0] = [ + '', %(path)s, ]
+abs__file__ = os.path.abspath( __file__ ) +sys.executable = abs__file__ +del ( __file__ ) + _interactive = True if len(sys.argv) > 1: import getopt @@ -914,7 +920,12 @@
if _args: sys.argv[:] = _args - execfile(sys.argv[0]) + f = sys.argv[0] + absf = os.path.abspath(f) + p = os.path.split( absf )[0] + sys.path[0] = os.path.join( p ) + __file__ = absf + execfile( f )
if _interactive: import code _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org

Actually, I'm a bit unclear as to how to test this in a useful way: do you think it is sufficient just to test that the content of the script generated contains specific text (that doesn't guarantee the script that is generated actually works!)? Thanks Miles Jim Fulton wrote:
Much thanks. Can you also supply a test? Better yet, since you are a zope contributor, you could just check in the change, including the test.
Jim
On Jul 19, 2007, at 5:21 PM, Miles wrote:
Hi,
That's correct. This is a limitation in zc.recipe.egg; we're open to patches that improve the generated interpreter script.
Thanks for confirming, I wasn't sure if it was like that for a reason.
I attach a patch that fixes up some other parameters so the generated interpreter script's behaviour is less distinguis matches what you get when you start the python interpreter more exactly. Works for me, but I'd appreciate some more eyes...
Miles
Index: zc.buildout/src/zc/buildout/easy_install.py =================================================================== --- zc.buildout/src/zc/buildout/easy_install.py (revision 78190) +++ zc.buildout/src/zc/buildout/easy_install.py (working copy) @@ -896,11 +896,17 @@ py_script_template = '''\ #!%(python)s import sys - +import os + sys.path[0:0] = [ + '', %(path)s, ]
+abs__file__ = os.path.abspath( __file__ ) +sys.executable = abs__file__ +del ( __file__ ) + _interactive = True if len(sys.argv) > 1: import getopt @@ -914,7 +920,12 @@
if _args: sys.argv[:] = _args - execfile(sys.argv[0]) + f = sys.argv[0] + absf = os.path.abspath(f) + p = os.path.split( absf )[0] + sys.path[0] = os.path.join( p ) + __file__ = absf + execfile( f )
if _interactive: import code _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org

On Jul 19, 2007, at 6:04 PM, Miles Waller wrote:
Actually, I'm a bit unclear as to how to test this in a useful way: do you think it is sufficient just to test that the content of the script generated contains specific text (that doesn't guarantee the script that is generated actually works!)?
You could use the generated script to run another script imports and uses a module that is in the current working directory. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
participants (4)
-
Fred L. Drake, Jr.
-
Jim Fulton
-
Miles
-
Miles Waller