[Checkins] SVN: zc.buildout/branches/gary-8/ add explanatory comments; extend test to show that scripts honor explicit PYTHONPATH
Gary Poster
gary.poster at canonical.com
Fri Mar 19 15:12:57 EDT 2010
Log message for revision 110067:
add explanatory comments; extend test to show that scripts honor explicit PYTHONPATH
Changed:
U zc.buildout/branches/gary-8/bootstrap/bootstrap.py
U zc.buildout/branches/gary-8/dev.py
U zc.buildout/branches/gary-8/src/zc/buildout/buildout.py
U zc.buildout/branches/gary-8/src/zc/buildout/easy_install.py
U zc.buildout/branches/gary-8/src/zc/buildout/tests.py
-=-
Modified: zc.buildout/branches/gary-8/bootstrap/bootstrap.py
===================================================================
--- zc.buildout/branches/gary-8/bootstrap/bootstrap.py 2010-03-19 15:32:03 UTC (rev 110066)
+++ zc.buildout/branches/gary-8/bootstrap/bootstrap.py 2010-03-19 19:12:57 UTC (rev 110067)
@@ -32,16 +32,20 @@
else:
quote = str
-# In order to be more robust in the face of system Pythons, we want to run
-# with site-packages loaded. This is somewhat tricky, in particular because
-# Python 2.6's distutils imports site, so starting with the -S flag is not
-# sufficient.
+# In order to be more robust in the face of system Pythons, we want to
+# run without site-packages loaded. This is somewhat tricky, in
+# particular because Python 2.6's distutils imports site, so starting
+# with the -S flag is not sufficient. However, we'll start with that:
if 'site' in sys.modules:
# We will restart with python -S.
args = sys.argv[:]
args[0:0] = [sys.executable, '-S']
args = map(quote, args)
os.execv(sys.executable, args)
+# Now we are running with -S. We'll get the clean sys.path, import site
+# because distutils will do it later, and then reset the path and clean
+# out any namespace packages from site-packages that might have been
+# loaded by .pth files.
clean_path = sys.path[:]
import site
sys.path[:] = clean_path
Modified: zc.buildout/branches/gary-8/dev.py
===================================================================
--- zc.buildout/branches/gary-8/dev.py 2010-03-19 15:32:03 UTC (rev 110066)
+++ zc.buildout/branches/gary-8/dev.py 2010-03-19 19:12:57 UTC (rev 110067)
@@ -30,16 +30,20 @@
else:
quote = str
-# In order to be more robust in the face of system Pythons, we want to run
-# with site-packages loaded. This is somewhat tricky, in particular because
-# Python 2.6's distutils imports site, so starting with the -S flag is not
-# sufficient.
+# In order to be more robust in the face of system Pythons, we want to
+# run without site-packages loaded. This is somewhat tricky, in
+# particular because Python 2.6's distutils imports site, so starting
+# with the -S flag is not sufficient. However, we'll start with that:
if 'site' in sys.modules:
# We will restart with python -S.
args = sys.argv[:]
args[0:0] = [sys.executable, '-S']
args = map(quote, args)
os.execv(sys.executable, args)
+# Now we are running with -S. We'll get the clean sys.path, import site
+# because distutils will do it later, and then reset the path and clean
+# out any namespace packages from site-packages that might have been
+# loaded by .pth files.
clean_path = sys.path[:]
import site
sys.path[:] = clean_path
Modified: zc.buildout/branches/gary-8/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/gary-8/src/zc/buildout/buildout.py 2010-03-19 15:32:03 UTC (rev 110066)
+++ zc.buildout/branches/gary-8/src/zc/buildout/buildout.py 2010-03-19 19:12:57 UTC (rev 110067)
@@ -903,6 +903,11 @@
if not __debug__:
args.insert(0, '-O')
args.insert(0, zc.buildout.easy_install._safe_arg(sys.executable))
+ # We want to make sure that our new site.py is used for rerunning
+ # buildout, so we put the partsdir in PYTHONPATH for our restart.
+ # This overrides any set PYTHONPATH, but since we generally are
+ # trying to run with a completely "clean" python (only the standard
+ # library) then that should be fine.
env = os.environ.copy()
env['PYTHONPATH'] = partsdir
if is_jython:
Modified: zc.buildout/branches/gary-8/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/gary-8/src/zc/buildout/easy_install.py 2010-03-19 15:32:03 UTC (rev 110066)
+++ zc.buildout/branches/gary-8/src/zc/buildout/easy_install.py 2010-03-19 19:12:57 UTC (rev 110067)
@@ -99,6 +99,9 @@
"print repr([os.path.normpath(p) for p in sys.path if p])"])
# Windows needs some (as yet to be determined) part of the real env.
env = os.environ.copy()
+ # We need to make sure that PYTHONPATH, which will often be set
+ # to include a custom buildout-generated site.py, is not set, or
+ # else we will not get an accurate sys.path for the executable.
env.pop('PYTHONPATH', None)
env.update(kwargs)
_proc = subprocess.Popen(
@@ -1487,6 +1490,10 @@
"fp.close; "
"print path" % (name,)]
env = os.environ.copy()
+ # We need to make sure that PYTHONPATH, which will often be set to
+ # include a custom buildout-generated site.py, is not set, or else
+ # we will not get an accurate value for the "real" site.py and
+ # sitecustomize.py.
env.pop('PYTHONPATH', None)
_proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
Modified: zc.buildout/branches/gary-8/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/gary-8/src/zc/buildout/tests.py 2010-03-19 15:32:03 UTC (rev 110066)
+++ zc.buildout/branches/gary-8/src/zc/buildout/tests.py 2010-03-19 19:12:57 UTC (rev 110067)
@@ -2294,6 +2294,51 @@
3
<BLANKLINE>
+If you have a PYTHONPATH in your environment, it will be honored, after
+the buildout-generated path.
+
+ >>> original_pythonpath = os.environ.get('PYTHONPATH')
+ >>> os.environ['PYTHONPATH'] = 'foo'
+ >>> test = (
+ ... "import subprocess, sys; subprocess.call("
+ ... "[sys.executable, '-c', "
+ ... "'import sys, pprint; pprint.pprint(sys.path)'])")
+ >>> generated = zc.buildout.easy_install.sitepackage_safe_scripts(
+ ... interpreter_bin_dir, ws, sys.executable, interpreter_parts_dir,
+ ... reqs=['demo'], interpreter='py',
+ ... script_initialization=test + '; sys.exit(0)')
+
+This works for the script. As you can see, /sample_buildout/foo is included
+right after the "parts" directory that contains site.py and sitecustomize.py.
+You can also see, actually more easily than in the other example, that we
+have the desired eggs available.
+
+ >>> print system(join(interpreter_bin_dir, 'demo')), # doctest: +ELLIPSIS
+ ['',
+ '/interpreter/parts/interpreter',
+ '/sample-buildout/foo',
+ ...
+ '/interpreter/eggs/demo-0.3-pyN.N.egg',
+ '/interpreter/eggs/demoneeded-1.1-pyN.N.egg']
+
+This also works for the generated interpreter, with identical results.
+
+ >>> print call_py(join(interpreter_bin_dir, 'py'), test),
+ ... # doctest: +ELLIPSIS
+ ['',
+ '/interpreter/parts/interpreter',
+ '/sample-buildout/foo',
+ ...
+ '/interpreter/eggs/demo-0.3-pyN.N.egg',
+ '/interpreter/eggs/demoneeded-1.1-pyN.N.egg']
+
+ >>> # Cleanup
+ >>> if original_pythonpath:
+ ... os.environ['PYTHONPATH'] = original_pythonpath
+ ... else:
+ ... del os.environ['PYTHONPATH']
+ ...
+
"""
def bootstrap_makes_buildout_that_works_with_system_python():
More information about the checkins
mailing list