[Python-modules-commits] [python-virtualenv] 04/08: Use the archive's wheels instead of the bundled wheels, by

Barry Warsaw barry at moszumanska.debian.org
Mon Feb 8 16:21:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

barry pushed a commit to branch master
in repository python-virtualenv.

commit 1d0dc78be4c0ec4e9bb0e46a38d63ed36470c47a
Author: Barry Warsaw <barry at debian.org>
Date:   Fri Oct 9 22:23:58 2015 +0200

    Use the archive's wheels instead of the bundled wheels, by
    
     prepending their paths onto the front of sys.path.  Also, when the venv is
     created, copy the system wheels into <venv>/lib/python-wheels for use by
     our patched pip wheel.  Make sure the command line script uses the system
     wheels first.
    Forwarded: not-needed
    
    Patch-Name: use-wheels.patch
---
 scripts/virtualenv |  9 +++++++++
 setup.py           |  4 ++--
 virtualenv.py      | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/scripts/virtualenv b/scripts/virtualenv
index 418bd79..7dd0203 100644
--- a/scripts/virtualenv
+++ b/scripts/virtualenv
@@ -1,3 +1,12 @@
 #!/usr/bin/python3
 import virtualenv
+
+# Debian: Barry Warsaw <barry at debian.org> 2014-06-02
+# Instead of using the bundled wheels, use the ones in the archive.
+import sys
+for path in virtualenv.find_wheels(virtualenv.DEBIAN_WHEEL_DEPS,
+                                   ['/usr/share/python-wheels']):
+    if path not in sys.path:
+        sys.path.insert(0, path)
+
 virtualenv.main()
diff --git a/setup.py b/setup.py
index 69e072c..8e16ced 100644
--- a/setup.py
+++ b/setup.py
@@ -122,6 +122,6 @@ setup(
     url='https://virtualenv.pypa.io/',
     license='MIT',
     py_modules=['virtualenv'],
-    packages=['virtualenv_support'],
-    package_data={'virtualenv_support': ['*.whl']},
+    #packages=['virtualenv_support'],
+    #package_data={'virtualenv_support': ['*.whl']},
     **setup_params)
diff --git a/virtualenv.py b/virtualenv.py
index c669b36..4482aa7 100755
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -36,6 +36,12 @@ except ImportError:
 __version__ = "14.0.5"
 virtualenv_version = __version__  # legacy
 
+# Debian: Barry Warsaw <barry at debian.org> 2014-06-06
+DEBIAN_WHEEL_DEPS = [
+    os.path.basename(whl).split('-')[0]
+    for whl in glob.glob('/usr/share/python-wheels/*.whl')
+    ]
+
 if sys.version_info < (2, 6):
     print('ERROR: %s' % sys.exc_info()[1])
     print('ERROR: this script requires Python 2.6 or greater.')
@@ -393,7 +399,11 @@ def _find_file(filename, dirs):
 
 def file_search_dirs():
     here = os.path.dirname(os.path.abspath(__file__))
-    dirs = [here, join(here, 'virtualenv_support')]
+    # Debian: Barry Warsaw <barry at debian.org> 2015-06-11
+    # Don't include the bundled wheels in the search dirs, since we strip them
+    # out in favor of the system wheels.
+    #dirs = [here, join(here, 'virtualenv_support')]
+    dirs = [here, '/usr/share/python-wheels/']
     if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
         # Probably some boot script; just in case virtualenv is installed...
         try:
@@ -734,7 +744,16 @@ def call_subprocess(cmd, show_stdout=True,
             for varname in remove_from_env:
                 env.pop(varname, None)
     else:
-        env = None
+        env = {}
+    # Debian: Barry Warsaw <barry at debian.org> 2014-06-06
+    # We're about to execute $python -c "import sys, pip ..." and run
+    # pip.main().  We have to make sure to find pip and setuptools via the
+    # wheels if they exist.
+    syspath_parts = env.get('PYTHONPATH', '').split(os.pathsep)
+    for path in find_wheels(DEBIAN_WHEEL_DEPS, ['/usr/share/python-wheels']):
+        if path not in syspath_parts:
+            syspath_parts.insert(0, path)
+    env['PYTHONPATH'] = os.pathsep.join(syspath_parts)
     try:
         proc = subprocess.Popen(
             cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
@@ -887,6 +906,31 @@ def create_environment(home_dir, site_packages=False, clear=False,
 
     to_install = []
 
+    # Debian: Barry Warsaw <barry at debian.org> 2014-06-06
+    # Copy system wheels into the venv directory where our hacked pip will
+    # search, i.e. <venv>/share/python-wheels.
+    destdir = os.path.join(home_dir, 'share', 'python-wheels')
+    try:
+        # The directory could exist.  Because this code may run under Python
+        # 2, we can't use `exist_ok=True`.  Catch and ignore the old way.
+        os.makedirs(destdir)
+    except OSError as error:
+        if error.errno != errno.EEXIST:
+            raise
+    for project in DEBIAN_WHEEL_DEPS:
+        wheel_names = glob.glob(
+            '/usr/share/python-wheels/{}-*.whl'.format(project))
+        if len(wheel_names) == 0:
+            raise RuntimeError('missing dependency wheel %s' % project)
+        assert len(wheel_names) == 1, wheel_names
+        wheel_name = os.path.basename(wheel_names[0])
+        path = os.path.join('/usr/share/python-wheels', wheel_name)
+        with open(path, 'rb') as fp:
+            whl = fp.read()
+        dest = os.path.join(destdir, wheel_name)
+        with open(dest, 'wb') as fp:
+            fp.write(whl)
+
     if not no_setuptools:
         to_install.append('setuptools')
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-virtualenv.git



More information about the Python-modules-commits mailing list