[Python-modules-commits] [python-pip] 07/14: Complete the dirtbike port.

Barry Warsaw barry at moszumanska.debian.org
Fri Jan 29 15:52:08 UTC 2016


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

barry pushed a commit to branch dirtbike
in repository python-pip.

commit d2fe1c1711f1260b5b04b26600e05819d75d98e5
Author: Barry Warsaw <barry at python.org>
Date:   Wed Jan 27 11:55:27 2016 -0500

    Complete the dirtbike port.
    
    Also, generate our own /usr/bin/pip{,3} since console_scripts doesn't do
    the right thing for us (it imports pkg_resources before hacking sys.path
    for wheels).
---
 debian/changelog  |  2 --
 debian/makepip.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/rules      | 11 ++++---
 3 files changed, 93 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index dfdcb1a..a6c7677 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,14 +1,12 @@
 python-pip (7.1.2-1) UNRELEASED; urgency=medium
 
   * DO NOT RELEASE.  TODO:
-    - Finish up dirtbike and use it for rewheeling.
     - File ITP and get progress 1.2 into Debian, or port to progressbar
       which is already in Debian.
     - Build python-ipaddress-whl or rewheel it package.
     - File ITP and upload 15.2 into Debian
     - Update Debian Python policy to name the new dependencies, all of
       which must be installed as -whl.  -- or rewheel
-    - Pass `-m 'not network` to test suite
   * New upstream release.
   * d/control:
     - Update python-pip-whl binary package's Depends since we will be
diff --git a/debian/makepip.py b/debian/makepip.py
new file mode 100644
index 0000000..9eeb98f
--- /dev/null
+++ b/debian/makepip.py
@@ -0,0 +1,86 @@
+"""Make the /usr/bin/pip* scripts which honor the distro wheels."""
+
+TEMPLATE = """\
+#!{shebang}
+# GENERATED BY DEBIAN ON {date} UTC
+
+import os
+import sys
+from glob import glob
+
+# Upstream pip vendorizes a bunch of its dependencies.  Debian de-vendorizes
+# (unbundles) these dependencies to be compliant with Debian policy.  Instead,
+# these dependencies are packaged as wheel (.whl) files in a known location.
+# When pip itself executes, we have to arrange for these wheels to show up
+# earlier on sys.path than any other version of these packages, otherwise
+# things can break.  See for example Bug #744145.
+#
+# The location of the wheels differs depending on whether we're inside or
+# outside a virtual environment, regardless of whether that venv was created
+# with virtualenv or pyvenv.  The first thing we have to do is figure out if
+# we're inside or outside a venv, then search the appropriate wheel directory
+# and add all the .whls found there to the front of sys.path.  As per Debian
+# Python Policy, only the wheels needed to support this de-vendorization will
+# be present, so it's safe to add them all.
+#
+# venv determination is a bit of a black art, but this algorithm should work
+# in both Python 2 (virtualenv-only) and Python 3 (pyvenv and virtualenv).  -
+# updated by barry at debian.org 2015-02-25
+
+base_prefix = getattr(sys, 'base_prefix', None)
+real_prefix = getattr(sys, 'real_prefix', None)
+if base_prefix is None:
+    # Python 2 has no base_prefix at all.  It also has no pyvenv.  Fall back
+    # to checking real_prefix.
+    if real_prefix is None:
+        # We are not in a venv.
+        in_venv = False
+    else:
+        # We're in a Python 2 virtualenv created venv, but real_prefix should
+        # never be the same as sys.prefix.
+        assert sys.prefix != real_prefix
+        in_venv = True
+elif sys.prefix != base_prefix:
+    # We're in a Python 3, pyvenv created venv.
+    in_venv = True
+elif real_prefix is None:
+    # We're in Python 3, outside a venv, but base better equal prefix.
+    assert sys.prefix == base_prefix
+    in_venv = False
+else:
+    # We're in a Python 3, virtualenv created venv.
+    assert real_prefix != sys.prefix
+    in_venv = True
+
+
+if in_venv:
+    wheel_dir = os.path.join(sys.prefix, 'lib', 'python-wheels')
+else:
+    wheel_dir = '/usr/share/python-wheels'
+
+
+# We'll add all the wheels we find to the front of sys.path so that they're
+# found first, even if the same dependencies are available in site-packages.
+sys.path[0:0] = glob(os.path.join(wheel_dir, '*.whl'))
+
+# Run the main entry point, similarly to how setuptools does it, but because
+# we didn't install the actual entry point from setup.py, don't use the
+# pkg_resources API.
+from pip import main
+if __name__ == '__main__':
+    sys.exit(main())
+"""
+
+# This is a one-off script, so just do stupid simple argument parsing.
+
+import sys
+from datetime import datetime
+
+substitutions = dict(
+    shebang=sys.argv[1],
+    date=str(datetime.utcnow().replace(microsecond=0)),
+    )
+
+output_file = sys.argv[2]
+with open(output_file, 'w', encoding='utf-8') as fp:
+    print(TEMPLATE.format(**substitutions), end='', file=fp)
diff --git a/debian/rules b/debian/rules
index 3714c7e..5846c46 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,6 +6,7 @@ export DH_VERBOSE=1
 
 export PIP_NO_VENDOR_FOR_DOWNSTREAM=1
 
+
 %:
 	dh $@ --with python2,python3 --buildsystem=pybuild
 
@@ -38,13 +39,15 @@ override_dh_auto_test:
 
 override_dh_python3:
 	dh_python3
-	rm -f debian/python3-pip/usr/bin/pip
-	rm -f debian/python3-pip/usr/bin/pip3.?
-	rm -rf debian/python3-pip/usr/lib/python3.?
+	mkdir -p debian/python3-pip/usr/bin
+	python3 debian/makepip.py /usr/bin/python3 \
+		debian/python3-pip/usr/bin/pip3
 
 override_dh_python2:
 	dh_python2
-	rm -f debian/python-pip/usr/bin/pip2.?
+	mkdir -p debian/python-pip/usr/bin
+	python3 debian/makepip.py /usr/bin/python2 \
+		debian/python-pip/usr/bin/pip
 
 override_dh_auto_install:
 	dh_auto_install

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



More information about the Python-modules-commits mailing list