From b7b8a713d9f1ebac6430fd0fc10175ed37b834ee Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar@redhat.com>
Date: Thu, 18 Mar 2021 13:08:52 +0100
Subject: [PATCH] rpm
---
virtualenv.py | 66 ++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 55 insertions(+), 11 deletions(-)
diff --git a/virtualenv.py b/virtualenv.py
index 5699998..9854324 100755
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -39,9 +39,9 @@ except ImportError:
__version__ = "15.1.0"
virtualenv_version = __version__ # legacy
-if sys.version_info < (2, 6):
+if sys.version_info < (2, 7):
print('ERROR: %s' % sys.exc_info()[1])
- print('ERROR: this script requires Python 2.6 or greater.')
+ print('ERROR: this script requires Python 2.7 or greater.')
sys.exit(101)
try:
@@ -399,6 +399,8 @@ def _find_file(filename, dirs):
def file_search_dirs():
here = os.path.dirname(os.path.abspath(__file__))
dirs = [here, join(here, 'virtualenv_support')]
+ dirs.insert(1, '/usr/share/python{}-wheels'.format(sys.version_info[0]))
+ dirs.insert(1, '/usr/share/python{}{}-wheels'.format(*sys.version_info[:2]))
if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
# Probably some boot script; just in case virtualenv is installed...
try:
@@ -859,7 +861,12 @@ def install_wheel(project_names, py_executable, search_dirs=None,
import tempfile
import os
- import pip
+ try:
+ from pip._internal import main as _main
+ if type(_main) is type(sys): # <type 'module'>
+ _main = _main.main # nested starting in Pip 19.3
+ except ImportError:
+ from pip import main as _main
try:
cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
@@ -878,7 +885,7 @@ def install_wheel(project_names, py_executable, search_dirs=None,
args += ["--cert", cert_file.name]
args += sys.argv[1:]
- sys.exit(pip.main(args))
+ sys.exit(_main(args))
finally:
if cert_file is not None:
os.remove(cert_file.name)
@@ -1038,20 +1045,57 @@ def change_prefix(filename, dst_prefix):
assert False, "Filename %s does not start with any of these prefixes: %s" % \
(filename, prefixes)
-def copy_required_modules(dst_prefix, symlink):
- import imp
+def find_module_filename(modname):
+ if sys.version_info < (3, 4):
+ # noinspection PyDeprecation
+ import imp
+
+ try:
+ file_handler, filepath, _ = imp.find_module(modname)
+ except ImportError:
+ return None
+ else:
+ if file_handler is not None:
+ file_handler.close()
+ return filepath
+ else:
+ import importlib.util
+ if sys.version_info < (3, 5):
+
+ def find_spec(modname):
+ # noinspection PyDeprecation
+ loader = importlib.find_loader(modname)
+ if loader is None:
+ return None
+ else:
+ return importlib.util.spec_from_loader(modname, loader)
+
+ else:
+ find_spec = importlib.util.find_spec
+
+ spec = find_spec(modname)
+ if spec is None:
+ return None
+ if not os.path.exists(spec.origin):
+ # https://bitbucket.org/pypy/pypy/issues/2944/origin-for-several-builtin-modules
+ # on pypy3, some builtin modules have a bogus build-time file path, ignore them
+ return None
+ filepath = spec.origin
+ # https://www.python.org/dev/peps/pep-3147/#file guarantee to be non-cached
+ if os.path.basename(filepath) == "__init__.py":
+ filepath = os.path.dirname(filepath)
+ return filepath
+
+def copy_required_modules(dst_prefix, symlink):
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:
+ filename = find_module_filename(modname)
+ if filename is None:
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'))):
--
2.30.2