diff options
author | Donald Stufft <donald@stufft.io> | 2014-12-23 21:46:52 -0500 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2014-12-23 21:46:52 -0500 |
commit | ae81707284cbc28f11cb1538363ae2a537da4bf0 (patch) | |
tree | 972b0de54526fc8abea314f8cdfc7e6274fc73d1 /virtualenv.py | |
parent | d73e30180ac8e6f6ad365d43fd3693afdcd51eaa (diff) | |
download | virtualenv-ae81707284cbc28f11cb1538363ae2a537da4bf0.tar.gz |
Revert "Merge pull request #674 from mgedmin/fix-sys-path-better"
This reverts commit 920d7c71d800ba4c0da8fcac605cdf0adfe46f3a, reversing
changes made to 23e66c9429b8f51046e4efc0ab39b633254d3053.
Diffstat (limited to 'virtualenv.py')
-rwxr-xr-x | virtualenv.py | 68 |
1 files changed, 39 insertions, 29 deletions
diff --git a/virtualenv.py b/virtualenv.py index 90f4212..3a163ea 100755 --- a/virtualenv.py +++ b/virtualenv.py @@ -5,8 +5,7 @@ __version__ = "12.1.dev0" virtualenv_version = __version__ # legacy -# NB: avoid placing additional imports here, before sys.path is fixed! - +import base64 import sys import os @@ -30,7 +29,6 @@ import os if os.environ.get('VIRTUALENV_INTERPRETER_RUNNING'): del sys.path[0] -import base64 import codecs import optparse import re @@ -1108,33 +1106,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): |