diff options
author | Donald Stufft <donald@stufft.io> | 2014-12-23 21:57:46 -0500 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2014-12-23 21:57:46 -0500 |
commit | ecf572da011aa0d3a1c96e840e72069e49f26bf6 (patch) | |
tree | c1e5a65dd82fb22f0934d30ced667bf05132084b /virtualenv.py | |
parent | a331207e2efef23b663dcfff409c144f60ab1272 (diff) | |
parent | a19b0dc4737a3af57466df584f47333c750f279e (diff) | |
download | virtualenv-12.0.4.tar.gz |
Merge branch 'release/12.0.4'12.0.4
Diffstat (limited to 'virtualenv.py')
-rwxr-xr-x | virtualenv.py | 93 |
1 files changed, 41 insertions, 52 deletions
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): |