Package: python-virtualenv / 1.11.6+ds-1

use-wheels.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Description: 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.
Author: Barry Warsaw <barry@debian.org>
Forwarded: not-needed

--- a/scripts/virtualenv
+++ b/scripts/virtualenv
@@ -1,3 +1,12 @@
 #!/usr/bin/python3
 import virtualenv
+
+# Debian: Barry Warsaw <barry@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()
--- a/setup.py
+++ b/setup.py
@@ -83,6 +83,6 @@
     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)
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -23,6 +23,10 @@
 import subprocess
 import tarfile
 
+# Debian: Barry Warsaw <barry@debian.org> 2014-06-06
+DEBIAN_WHEEL_DEPS = ['chardet', 'colorama', 'distlib', 'html5lib',
+                     'pip', 'requests', 'setuptools', 'six', 'urllib3']
+
 if sys.version_info < (2, 6):
     print('ERROR: %s' % sys.exc_info()[1])
     print('ERROR: this script requires Python 2.6 or greater.')
@@ -526,7 +530,8 @@
 def file_search_dirs():
     here = os.path.dirname(os.path.abspath(__file__))
     dirs = ['.', here,
-            join(here, 'virtualenv_support')]
+            #join(here, 'virtualenv_support')]
+            '/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:
@@ -855,7 +860,16 @@
             for varname in remove_from_env:
                 env.pop(varname, None)
     else:
-        env = None
+        env = {}
+    # Debian: Barry Warsaw <barry@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,
@@ -985,6 +999,31 @@
 
     install_distutils(home_dir)
 
+    # Debian: Barry Warsaw <barry@debian.org> 2014-06-06
+    # Copy system wheels into the venv directory where our hacked pip will
+    # search, i.e. <venv>/lib/python-wheels.
+    destdir = os.path.join(home_dir, 'lib', '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 = ['setuptools']
         if not no_pip: