summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/changes.rst8
-rwxr-xr-xvirtualenv.py93
2 files changed, 49 insertions, 52 deletions
diff --git a/docs/changes.rst b/docs/changes.rst
index 985959e..cb84d68 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -1,6 +1,14 @@
Release History
===============
+12.0.4 (2014-22-23)
+~~~~~~~~~~~~~~~~~~~
+
+* Revert the fix to ``-p`` on Debian based pythons as it was broken in other
+ situations.
+
+* Revert several sys.path changes new in 12.0 which were breaking virtualenv.
+
12.0.3 (2014-22-23)
~~~~~~~~~~~~~~~~~~~
diff --git a/virtualenv.py b/virtualenv.py
index 48009ba..8501e9d 100755
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -2,35 +2,12 @@
"""Create a "virtual" Python installation
"""
-__version__ = "12.0.3"
+__version__ = "12.0.4"
virtualenv_version = __version__ # legacy
-# NB: avoid placing additional imports here, before sys.path is fixed!
-
+import base64
import sys
import os
-
-#
-# RATIONALE:
-# This script is both it's own "host" and "guest". If it's running in "guest
-# mode" (inside the virtualenv interpreter), it's essentially invoked via:
-# /path/to/python /path/to/this/script.py
-#
-# Which, by the nature of Python, will put `/path/to/this` on the system path
-# as the first argument. Now this can cause many subtle bugs, because the
-# rest of the script is now looking to import from the "host" Python version
-# first. This has been especially troublesome when trying to create a Python
-# 3 "guest" env using a Python 2 "host", but even with minor Python
-# differences, there may been some bleeding between environments that doesn't
-# stand out as obviously.
-#
-# This removes the first argument off the system path, to avoid any accidental
-# usage of the "host" library directories.
-#
-if os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
- del sys.path[0]
-
-import base64
import codecs
import optparse
import re
@@ -804,7 +781,7 @@ def main():
file = __file__
if file.endswith('.pyc'):
file = file[:-1]
- popen = subprocess.Popen([interpreter, "-S", file] + sys.argv[1:], env=env)
+ popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
raise SystemExit(popen.wait())
if not args:
@@ -1108,33 +1085,45 @@ def change_prefix(filename, dst_prefix):
def copy_required_modules(dst_prefix, symlink):
import imp
- for modname in REQUIRED_MODULES:
- if modname in sys.builtin_module_names:
- logger.info("Ignoring built-in bootstrap module: %s" % modname)
- continue
- try:
- f, filename, _ = imp.find_module(modname)
- except ImportError:
- logger.info("Cannot import bootstrap module: %s" % modname)
- else:
- if f is not None:
- f.close()
- # special-case custom readline.so on OS X, but not for pypy:
- if modname == 'readline' and sys.platform == 'darwin' and not (
- is_pypy or filename.endswith(join('lib-dynload', 'readline.so'))):
- dst_filename = join(dst_prefix, 'lib', 'python%s' % sys.version[:3], 'readline.so')
- elif modname == 'readline' and sys.platform == 'win32':
- # special-case for Windows, where readline is not a
- # standard module, though it may have been installed in
- # site-packages by a third-party package
- pass
+ # If we are running under -p, we need to remove the current
+ # directory from sys.path temporarily here, so that we
+ # definitely get the modules from the site directory of
+ # the interpreter we are running under, not the one
+ # virtualenv.py is installed under (which might lead to py2/py3
+ # incompatibility issues)
+ _prev_sys_path = sys.path
+ if os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'):
+ sys.path = sys.path[1:]
+ try:
+ for modname in REQUIRED_MODULES:
+ if modname in sys.builtin_module_names:
+ logger.info("Ignoring built-in bootstrap module: %s" % modname)
+ continue
+ try:
+ f, filename, _ = imp.find_module(modname)
+ except ImportError:
+ logger.info("Cannot import bootstrap module: %s" % modname)
else:
- dst_filename = change_prefix(filename, dst_prefix)
- copyfile(filename, dst_filename, symlink)
- if filename.endswith('.pyc'):
- pyfile = filename[:-1]
- if os.path.exists(pyfile):
- copyfile(pyfile, dst_filename[:-1], symlink)
+ if f is not None:
+ f.close()
+ # special-case custom readline.so on OS X, but not for pypy:
+ if modname == 'readline' and sys.platform == 'darwin' and not (
+ is_pypy or filename.endswith(join('lib-dynload', 'readline.so'))):
+ dst_filename = join(dst_prefix, 'lib', 'python%s' % sys.version[:3], 'readline.so')
+ elif modname == 'readline' and sys.platform == 'win32':
+ # special-case for Windows, where readline is not a
+ # standard module, though it may have been installed in
+ # site-packages by a third-party package
+ pass
+ else:
+ dst_filename = change_prefix(filename, dst_prefix)
+ copyfile(filename, dst_filename, symlink)
+ if filename.endswith('.pyc'):
+ pyfile = filename[:-1]
+ if os.path.exists(pyfile):
+ copyfile(pyfile, dst_filename[:-1], symlink)
+ finally:
+ sys.path = _prev_sys_path
def subst_path(prefix_path, prefix, home_dir):