Skip to content

Commit 1028b28

Browse files
committed
Switch to patches
1 parent 6051433 commit 1028b28

File tree

5 files changed

+108
-97
lines changed

5 files changed

+108
-97
lines changed

pip/_vendor/README.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Policy
1515
pure Python.
1616

1717
* Any modifications made to libraries **MUST** be noted in
18-
``pip/_vendor/README.rst`` and **MUST** be automatically applied via
19-
``tasks/vendoring.py``.
18+
``pip/_vendor/README.rst`` and their corresponding patches **MUST** be
19+
included ``tasks/vendoring/patches``.
2020

2121

2222
Rationale
@@ -108,9 +108,11 @@ Modifications
108108
Automatic Vendoring
109109
-------------------
110110

111-
Vendoring is automated via ``tasks/vendoring.py`` from the content of
112-
``pip/_vendor/vendor.txt``. Special cases adaptation MUST be reported in the
113-
``tasks/vendoring.py`` file. Launch it via ``invoke vendoring.update``.
111+
Vendoring is automated via the ``vendoring.update`` task (defined in
112+
``tasks/vendoring/__init__.py``) from the content of
113+
``pip/_vendor/vendor.txt`` and the different patches in
114+
``tasks/vendoring/patches/``.
115+
Launch it via ``invoke vendoring.update`` (you will need ``invoke>=0.13.0``).
114116

115117

116118
Debundling

tasks/vendoring.py renamed to tasks/vendoring/__init__.py

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -16,82 +16,6 @@
1616
)
1717

1818

19-
SPECIAL_CASES = (
20-
# Modified distro to delay importing argparse to avoid errors on 2.6
21-
(
22-
'distro.py',
23-
"""\
24-
import logging
25-
import argparse
26-
import subprocess""",
27-
"""\
28-
import logging
29-
import subprocess""",
30-
),
31-
(
32-
'distro.py',
33-
r'def main():',
34-
r'def main():\n import argparse\n',
35-
),
36-
# Remove unvendored requests special case
37-
(
38-
'cachecontrol/compat.py',
39-
"""\
40-
# Handle the case where the requests module has been patched to not have
41-
# urllib3 bundled as part of its source.
42-
try:
43-
from pip._vendor.requests.packages.urllib3.response import HTTPResponse
44-
except ImportError:
45-
from urllib3.response import HTTPResponse
46-
47-
try:
48-
from pip._vendor.requests.packages.urllib3.util import is_fp_closed
49-
except ImportError:
50-
from urllib3.util import is_fp_closed""",
51-
"""\
52-
from pip._vendor.requests.packages.urllib3.response import HTTPResponse
53-
from pip._vendor.requests.packages.urllib3.util import is_fp_closed""",
54-
),
55-
# requests has been modified *not* to optionally load any C dependencies
56-
(
57-
'requests/__init__.py',
58-
"""\
59-
try:
60-
from .packages.urllib3.contrib import pyopenssl
61-
pyopenssl.inject_into_urllib3()
62-
except ImportError:
63-
pass""",
64-
"""\
65-
# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this
66-
# prevents upgrading cryptography.
67-
# try:
68-
# from .packages.urllib3.contrib import pyopenssl
69-
# pyopenssl.inject_into_urllib3()
70-
# except ImportError:
71-
# pass""",
72-
),
73-
(
74-
'requests/compat.py',
75-
"""\
76-
try:
77-
import simplejson as json
78-
except (ImportError, SyntaxError):
79-
# simplejson does not support Python 3.2, it throws a SyntaxError
80-
# because of u'...' Unicode literals.
81-
import json""",
82-
"""\
83-
# Note: We've patched out simplejson support in pip because it prevents
84-
# upgrading simplejson on Windows.
85-
# try:
86-
# import simplejson as json
87-
# except (ImportError, SyntaxError):
88-
# # simplejson does not support Python 3.2, it throws a SyntaxError
89-
# # because of u'...' Unicode literals.
90-
import json""",
91-
)
92-
)
93-
94-
9519
def drop_dir(path):
9620
shutil.rmtree(str(path))
9721

@@ -148,19 +72,9 @@ def rewrite_file_imports(item, vendored_libs):
14872
item.write_text(text)
14973

15074

151-
def apply_special_cases(vendor_dir, special_cases):
152-
for filename, to_replace, replacement in special_cases:
153-
patched_file = vendor_dir / filename
154-
text = patched_file.read_text()
155-
text, nb_apply = re.subn(
156-
# Escape parenthesis for re.subn
157-
to_replace.replace('(', '\\(').replace(')', '\\)'),
158-
replacement,
159-
text,
160-
)
161-
# Make sure the patch is correctly applied
162-
assert nb_apply, filename
163-
patched_file.write_text(text)
75+
def apply_patch(ctx, patch_file_path):
76+
log('Applying patch %s' % patch_file_path.name)
77+
ctx.run('git apply %s' % patch_file_path)
16478

16579

16680
def vendor(ctx, vendor_dir):
@@ -196,9 +110,11 @@ def vendor(ctx, vendor_dir):
196110
elif item.name not in FILE_WHITE_LIST:
197111
rewrite_file_imports(item, vendored_libs)
198112

199-
# Special cases
200-
log("Dealing with special cases")
201-
apply_special_cases(vendor_dir, SPECIAL_CASES)
113+
# Special cases: apply stored patches
114+
log("Apply patches")
115+
patch_dir = Path(__file__).parent / 'patches'
116+
for patch in patch_dir.glob('*.patch'):
117+
apply_patch(ctx, patch)
202118

203119

204120
@invoke.task(name=TASK_NAME)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/pip/_vendor/cachecontrol/compat.py b/pip/_vendor/cachecontrol/compat.py
2+
index 54ec211..018e6ac 100644
3+
--- a/pip/_vendor/cachecontrol/compat.py
4+
+++ b/pip/_vendor/cachecontrol/compat.py
5+
@@ -10,17 +10,8 @@ except ImportError:
6+
import pickle
7+
8+
9+
-# Handle the case where the requests module has been patched to not have
10+
-# urllib3 bundled as part of its source.
11+
-try:
12+
- from pip._vendor.requests.packages.urllib3.response import HTTPResponse
13+
-except ImportError:
14+
- from urllib3.response import HTTPResponse
15+
-
16+
-try:
17+
- from pip._vendor.requests.packages.urllib3.util import is_fp_closed
18+
-except ImportError:
19+
- from urllib3.util import is_fp_closed
20+
+from pip._vendor.requests.packages.urllib3.response import HTTPResponse
21+
+from pip._vendor.requests.packages.urllib3.util import is_fp_closed
22+
23+
# Replicate some six behaviour
24+
try:

tasks/vendoring/patches/distro.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/pip/_vendor/distro.py b/pip/_vendor/distro.py
2+
index 0afa527..9e7daad 100644
3+
--- a/pip/_vendor/distro.py
4+
+++ b/pip/_vendor/distro.py
5+
@@ -34,7 +34,6 @@ import sys
6+
import json
7+
import shlex
8+
import logging
9+
-import argparse
10+
import subprocess
11+
12+
13+
@@ -1052,6 +1051,8 @@ _distro = LinuxDistribution()
14+
15+
16+
def main():
17+
+ import argparse
18+
+
19+
logger = logging.getLogger(__name__)
20+
logger.setLevel(logging.DEBUG)
21+
logger.addHandler(logging.StreamHandler(sys.stdout))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/pip/_vendor/requests/__init__.py b/pip/_vendor/requests/__init__.py
2+
index 9c3b769..44f6836 100644
3+
--- a/pip/_vendor/requests/__init__.py
4+
+++ b/pip/_vendor/requests/__init__.py
5+
@@ -48,11 +48,13 @@ __license__ = 'Apache 2.0'
6+
__copyright__ = 'Copyright 2016 Kenneth Reitz'
7+
8+
# Attempt to enable urllib3's SNI support, if possible
9+
-try:
10+
- from .packages.urllib3.contrib import pyopenssl
11+
- pyopenssl.inject_into_urllib3()
12+
-except ImportError:
13+
- pass
14+
+# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this
15+
+# prevents upgrading cryptography.
16+
+# try:
17+
+# from .packages.urllib3.contrib import pyopenssl
18+
+# pyopenssl.inject_into_urllib3()
19+
+# except ImportError:
20+
+# pass
21+
22+
import warnings
23+
24+
diff --git a/pip/_vendor/requests/compat.py b/pip/_vendor/requests/compat.py
25+
index eb6530d..353ec29 100644
26+
--- a/pip/_vendor/requests/compat.py
27+
+++ b/pip/_vendor/requests/compat.py
28+
@@ -25,12 +25,14 @@ is_py2 = (_ver[0] == 2)
29+
#: Python 3.x?
30+
is_py3 = (_ver[0] == 3)
31+
32+
-try:
33+
- import simplejson as json
34+
-except (ImportError, SyntaxError):
35+
- # simplejson does not support Python 3.2, it throws a SyntaxError
36+
- # because of u'...' Unicode literals.
37+
- import json
38+
+# Note: We've patched out simplejson support in pip because it prevents
39+
+# upgrading simplejson on Windows.
40+
+# try:
41+
+# import simplejson as json
42+
+# except (ImportError, SyntaxError):
43+
+# # simplejson does not support Python 3.2, it throws a SyntaxError
44+
+# # because of u'...' Unicode literals.
45+
+import json
46+
47+
# ---------
48+
# Specifics

0 commit comments

Comments
 (0)