8000 Update to pip 19.3.1 · discord/rules_python@7ed8458 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ed8458

Browse files
committed
Update to pip 19.3.1
* Also updates setuptools and wheel * Use pkg_resources to parse METADATA
1 parent 748aa53 commit 7ed8458

File tree

6 files changed

+59
-38
lines changed

6 files changed

+59
-38
lines changed

packaging/piptool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def extract_packages(package_names):
6363
# Defeat pip's attempt to mangle sys.path
6464
saved_sys_path = sys.path
6565
sys.path = sys.path[:]
66-
import pip
66+
from pip._internal import main as _pip_main
6767
sys.path = saved_sys_path
6868

6969
import setuptools
@@ -77,9 +77,9 @@ def pip_main(argv):
7777
cert_path = os.path.join(cert_tmpdir, "cacert.pem")
7878
atexit.register(lambda: shutil.rmtree(cert_tmpdir, ignore_errors=True))
7979
with open(cert_path, "wb") as cert:
80-
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
80+
cert.write(pkgutil.get_data("pip._vendor.certifi", "cacert.pem"))
8181
argv = ["--isolated", "--disable-pip-version-check", "--cert", cert_path] + argv
82-
return pip.main(argv)
82+
return _pip_main.main(argv)
8383

8484
from packaging.whl import Wheel
8585

packaging/whl.py

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,51 @@
1919
import pkg_resources
2020
import re
2121
import zipfile
22+
from email.parser import Parser
23+
24+
25+
class WheelMetadata(pkg_resources.FileMetadata):
26+
"""Metadata handler for Wheels
27+
28+
This provider acts like FileMetadata, but returns
29+
"""
30+
31+
def __init__(self, path):
32+
self.path = path
33+
34+
def get_metadata(self, name):
35+
if name != 'METADATA':
36+
raise KeyError("No metadata except METADATA is available")
37+
38+
basename = os.path.basename(self.path)
39+
parts = basename.split('-')
40+
distribution, version = parts[0], parts[1]
41+
metadata_path = '{}-{}.dist-info/METADATA'.format(distribution, version)
42+
43+
with zipfile.ZipFile(self.path) as zf:
44+
# pkg_resources uses email.parser.Parser to parse METADATA, which doesn't support unicode
45+
# In order to solve this we have to either reimplement pkg_resources' parsing to not use email.parser
46+
# or strip Unicode characters. Since PEP 566 specifically references email.parser as the way to read
47+
# METADATA, stripping Unicode characters seems like the better solution for now, especially since this
48+
# shouldn't affect any information we care about for dependency resoltuion.
49+
metadata = zf.read(metadata_path).decode('ascii', 'ignore')
50+
return metadata
2251

2352

2453
class Wheel(object):
2554

2655
def __init__(self, path):
2756
self._path = path
28-
57+
58+
@property
59+
def _dist(self):
60+
try:
61+
return self.__dist
62+
except AttributeError:
63+
metadata = WheelMetadata(self.path())
64+
self.__dist = pkg_resources.DistInfoDistribution.from_filename(self.path(), metadata)
65+
return self.__dist
66+
2967
def path(self):
3068
return self._path
3169

@@ -55,22 +93,14 @@ def _dist_info(self):
5593
# google_cloud-0.27.0.dist-info
5694
return '{}-{}.dist-info'.format(self.distribution(), self.version())
5795

58-
def metadata(self):
59-
# Extract the structured data from metadata.json in the WHL's dist-info
60-
# directory.
96+
def _metadata(self):
97+
# Extract the structured data from METADATA file
6198
with zipfile.ZipFile(self.path(), 'r') as whl:
62-
# first check for metadata.json
63-
try:
64-
with whl.open(self._dist_info() + '/metadata.json') as f:
65-
return json.loads(f.read().decode< AD86 /span>("utf-8"))
66-
except KeyError:
67-
pass
68-
# fall back to METADATA file (https://www.python.org/dev/peps/pep-0427/)
6999
with whl.open(self._dist_info() + '/METADATA') as f:
70100
return self._parse_metadata(f.read().decode("utf-8"))
71101

72102
def name(self):
73-
return self.metadata().get('name')
103+
return self._metadata().get('name')
74104

75105
def dependencies(self, extra=None):
76106
"""Access the dependencies of this Wheel.
@@ -82,29 +112,20 @@ def dependencies(self, extra=None):
82112
Yields:
83113
the names of requirements from the metadata.json
84114
"""
85-
# TODO(mattmoor): Is there a schema to follow for this?
86-
dependency_set = set()
87-
88-
run_requires = self.metadata().get('run_requires', [])
89-
for requirement in run_requires:
90-
if requirement.get('extra') != extra:
91-
# Match the requirements for the extra we're looking for.
92-
continue
93-
marker = requirement.get('environment')
94-
if marker and not pkg_resources.evaluate_marker(marker):
95-
# The current environment does not match the provided PEP 508 marker,
96-
# so ignore this requirement.
97-
continue
98-
requires = requirement.get('requires', [])
99-
for entry in requires:
100-
# Strip off any trailing versioning data.
101-
parts = re.split('[ ><=()]', entry)
102-
dependency_set.add(parts[0])
115+
requires = set(self._dist.requires())
116+
if extra:
117+
requires = set(self._dist.requires(extras=(extra,))) - requires
103118

119+
dependency_set = set()
120+
for r in requires:
121+
name = r.project_name
122+
if r.extras:
123+
name += "[{0}]".format(",".join(sorted(r.extras)))
124+
dependency_set.add(name)
104125
return dependency_set
105126

106127
def extras(self):
107-
return self.metadata().get('extras', [])
128+
return self._dist.extras
108129

109130
def expand(self, directory):
110131
with zipfile.ZipFile(self.path(), 'r') as whl:

python/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pip==9.0.3
1+
pip==19.3.1
22
setuptools==44.0.0
3-
wheel==0.30.0a0
3+
wheel==0.33.6
44

55
# For tests
66
mock==2.0.0

tools/piptool.par

89.5 KB
Binary file not shown.

tools/update_tools/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ RUN apt-get update -y && apt-get install -y \
66
# which we're not using here, but let's be safe.
77
openjdk-8-jdk \
88
# These requirements are from the link above.
9-
pkg-config zip g++ zlib1g-dev unzip python3 \
9+
pkg-config zip g++ zlib1g-dev unzip python3 python3-dev \
1010
# And why should python3 have all the fun?
11-
python \
11+
python python-dev \
1212
# We also need git for git_repository to work. Maybe these other ones too.
1313
git unzip build-essential \
1414
# And wget for the below command.

tools/whltool.par

1.28 KB
Binary file not shown.

0 commit comments

Comments
 (0)
0