Skip to content

Commit 4b6311a

Browse files
ichard26sbidoul
authored andcommitted
Upgrade distlib to 0.3.9
1 parent dfe98c8 commit 4b6311a

File tree

13 files changed

+307
-513
lines changed

13 files changed

+307
-513
lines changed

news/distlib.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade distlib to 0.3.9

src/pip/_vendor/distlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
import logging
88

9-
__version__ = '0.3.8'
9+
__version__ = '0.3.9'
1010

1111

1212
class DistlibException(Exception):

src/pip/_vendor/distlib/compat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
217217
# Additionally check that `file` is not a directory, as on Windows
218218
# directories pass the os.access check.
219219
def _access_check(fn, mode):
220-
return (os.path.exists(fn) and os.access(fn, mode)
221-
and not os.path.isdir(fn))
220+
return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn))
222221

223222
# If we're given a path with a directory part, look it up directly rather
224223
# than referring to PATH directories. This includes checking relative to the

src/pip/_vendor/distlib/database.py

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,20 @@
2020
from . import DistlibException, resources
2121
from .compat import StringIO
2222
from .version import get_scheme, UnsupportedVersionError
23-
from .metadata import (Metadata, METADATA_FILENAME, WHEEL_METADATA_FILENAME,
24-
LEGACY_METADATA_FILENAME)
25-
from .util import (parse_requirement, cached_property, parse_name_and_version,
26-
read_exports, write_exports, CSVReader, CSVWriter)
23+
from .metadata import (Metadata, METADATA_FILENAME, WHEEL_METADATA_FILENAME, LEGACY_METADATA_FILENAME)
24+
from .util import (parse_requirement, cached_property, parse_name_and_version, read_exports, write_exports, CSVReader,
25+
CSVWriter)
2726

2827
__all__ = [
29-
'Distribution', 'BaseInstalledDistribution', 'InstalledDistribution',
30-
'EggInfoDistribution', 'DistributionPath'
28+
'Distribution', 'BaseInstalledDistribution', 'InstalledDistribution', 'EggInfoDistribution', 'DistributionPath'
3129
]
3230

3331
logger = logging.getLogger(__name__)
3432

3533
EXPORTS_FILENAME = 'pydist-exports.json'
3634
COMMANDS_FILENAME = 'pydist-commands.json'
3735

38-
DIST_FILES = ('INSTALLER', METADATA_FILENAME, 'RECORD', 'REQUESTED',
39-
'RESOURCES', EXPORTS_FILENAME, 'SHARED')
36+
DIST_FILES = ('INSTALLER', METADATA_FILENAME, 'RECORD', 'REQUESTED', 'RESOURCES', EXPORTS_FILENAME, 'SHARED')
4037

4138
DISTINFO_EXT = '.dist-info'
4239

@@ -134,29 +131,21 @@ def _yield_distributions(self):
134131
continue
135132
try:
136133
if self._include_dist and entry.endswith(DISTINFO_EXT):
137-
possible_filenames = [
138-
METADATA_FILENAME, WHEEL_METADATA_FILENAME,
139-
LEGACY_METADATA_FILENAME
140-
]
134+
possible_filenames = [METADATA_FILENAME, WHEEL_METADATA_FILENAME, LEGACY_METADATA_FILENAME]
141135
for metadata_filename in possible_filenames:
142-
metadata_path = posixpath.join(
143-
entry, metadata_filename)
136+
metadata_path = posixpath.join(entry, metadata_filename)
144137
pydist = finder.find(metadata_path)
145138
if pydist:
146139
break
147140
else:
148141
continue
149142

150143
with contextlib.closing(pydist.as_stream()) as stream:
151-
metadata = Metadata(fileobj=stream,
152-
scheme='legacy')
144+
metadata = Metadata(fileobj=stream, scheme='legacy')
153145
logger.debug('Found %s', r.path)
154146
seen.add(r.path)
155-
yield new_dist_class(r.path,
156-
metadata=metadata,
157-
env=self)
158-
elif self._include_egg and entry.endswith(
159-
('.egg-info', '.egg')):
147+
yield new_dist_class(r.path, metadata=metadata, env=self)
148+
elif self._include_egg and entry.endswith(('.egg-info', '.egg')):
160149
logger.debug('Found %s', r.path)
161150
seen.add(r.path)
162151
yield old_dist_class(r.path, self)
@@ -274,8 +263,7 @@ def provides_distribution(self, name, version=None):
274263
try:
275264
matcher = self._scheme.matcher('%s (%s)' % (name, version))
276265
except ValueError:
277-
raise DistlibException('invalid name or version: %r, %r' %
278-
(name, version))
266+
raise DistlibException('invalid name or version: %r, %r' % (name, version))
279267

280268
for dist in self.get_distributions():
281269
# We hit a problem on Travis where enum34 was installed and doesn't
@@ -390,10 +378,8 @@ def provides(self):
390378
def _get_requirements(self, req_attr):
391379
md = self.metadata
392380
reqts = getattr(md, req_attr)
393-
logger.debug('%s: got requirements %r from metadata: %r', self.name,
394-
req_attr, reqts)
395-
return set(
396-
md.get_requirements(reqts, extras=self.extras, env=self.context))
381+
logger.debug('%s: got requirements %r from metadata: %r', self.name, req_attr, reqts)
382+
return set(md.get_requirements(reqts, extras=self.extras, env=self.context))
397383

398384
@property
399385
def run_requires(self):
@@ -469,8 +455,7 @@ def __eq__(self, other):
469455
if type(other) is not type(self):
470456
result = False
471457
else:
472-
result = (self.name == other.name and self.version == other.version
473-
and self.source_url == other.source_url)
458+
result = (self.name == other.name and self.version == other.version and self.source_url == other.source_url)
474459
return result
475460

476461
def __hash__(self):
@@ -561,8 +546,7 @@ def __init__(self, path, metadata=None, env=None):
561546
if r is None:
562547
r = finder.find(LEGACY_METADATA_FILENAME)
563548
if r is None:
564-
raise ValueError('no %s found in %s' %
565-
(METADATA_FILENAME, path))
549+
raise ValueError('no %s found in %s' % (METADATA_FILENAME, path))
566550
with contextlib.closing(r.as_stream()) as stream:
567551
metadata = Metadata(fileobj=stream, scheme='legacy')
568552

@@ -580,8 +564,7 @@ def __init__(self, path, metadata=None, env=None):
580564
self.modules = data.splitlines()
581565

582566
def __repr__(self):
583-
return '<InstalledDistribution %r %s at %r>' % (
584-
self.name, self.version, self.path)
567+
return '<InstalledDistribution %r %s at %r>' % (self.name, self.version, self.path)
585568

586569
def __str__(self):
587570
return "%s %s" % (self.name, self.version)
@@ -703,8 +686,7 @@ def write_installed_files(self, paths, prefix, dry_run=False):
703686
size = '%d' % os.path.getsize(path)
704687
with open(path, 'rb') as fp:
705688
hash_value = self.get_hash(fp.read())
706-
if path.startswith(base) or (base_under_prefix
707-
and path.startswith(prefix)):
689+
if path.startswith(base) or (base_under_prefix and path.startswith(prefix)):
708690
path = os.path.relpath(path, base)
709691
writer.writerow((path, hash_value, size))
710692

@@ -746,8 +728,7 @@ def check_installed_files(self):
746728
with open(path, 'rb') as f:
747729
actual_hash = self.get_hash(f.read(), hasher)
748730
if actual_hash != hash_value:
749-
mismatches.append(
750-
(path, 'hash', hash_value, actual_hash))
731+
mismatches.append((path, 'hash', hash_value, actual_hash))
751732
return mismatches
752733

753734
@cached_property
@@ -829,9 +810,8 @@ def get_distinfo_file(self, path):
829810
# it's an absolute path?
830811
distinfo_dirname, path = path.split(os.sep)[-2:]
831812
if distinfo_dirname != self.path.split(os.sep)[-1]:
832-
raise DistlibException(
833-
'dist-info file %r does not belong to the %r %s '
834-
'distribution' % (path, self.name, self.version))
813+
raise DistlibException('dist-info file %r does not belong to the %r %s '
814+
'distribution' % (path, self.name, self.version))
835815

836816
# The file must be relative
837817
if path not in DIST_FILES:
@@ -857,8 +837,7 @@ def list_distinfo_files(self):
857837
yield path
858838

859839
def __eq__(self, other):
860-
return (isinstance(other, InstalledDistribution)
861-
and self.path == other.path)
840+
return (isinstance(other, InstalledDistribution) and self.path == other.path)
862841

863842
# See http://docs.python.org/reference/datamodel#object.__hash__
864843
__hash__ = object.__hash__
@@ -911,8 +890,7 @@ def parse_requires_data(data):
911890
if not line: # pragma: no cover
912891
continue
913892
if line.startswith('['): # pragma: no cover
914-
logger.warning(
915-
'Unexpected line: quitting requirement scan: %r', line)
893+
logger.warning('Unexpected line: quitting requirement scan: %r', line)
916894
break
917895
r = parse_requirement(line)
918896
if not r: # pragma: no cover
@@ -954,13 +932,11 @@ def parse_requires_path(req_path):
954932
else:
955933
# FIXME handle the case where zipfile is not available
956934
zipf = zipimport.zipimporter(path)
957-
fileobj = StringIO(
958-
zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
935+
fileobj = StringIO(zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
959936
metadata = Metadata(fileobj=fileobj, scheme='legacy')
960937
try:
961938
data = zipf.get_data('EGG-INFO/requires.txt')
962-
tl_data = zipf.get_data('EGG-INFO/top_level.txt').decode(
963-
'utf-8')
939+
tl_data = zipf.get_data('EGG-INFO/top_level.txt').decode('utf-8')
964940
requires = parse_requires_data(data.decode('utf-8'))
965941
except IOError:
966942
requires = None
@@ -990,8 +966,7 @@ def parse_requires_path(req_path):
990966
return metadata
991967

992968
def __repr__(self):
993-
return '<EggInfoDistribution %r %s at %r>' % (self.name, self.version,
994-
self.path)
969+
return '<EggInfoDistribution %r %s at %r>' % (self.name, self.version, self.path)
995970

996971
def __str__(self):
997972
return "%s %s" % (self.name, self.version)
@@ -1083,8 +1058,7 @@ def list_distinfo_files(self, absolute=False):
10831058
yield line
10841059

10851060
def __eq__(self, other):
1086-
return (isinstance(other, EggInfoDistribution)
1087-
and self.path == other.path)
1061+
return (isinstance(other, EggInfoDistribution) and self.path == other.path)
10881062

10891063
# See http://docs.python.org/reference/datamodel#object.__hash__
10901064
__hash__ = object.__hash__
@@ -1184,8 +1158,7 @@ def to_dot(self, f, skip_disconnected=True):
11841158
disconnected.append(dist)
11851159
for other, label in adjs:
11861160
if label is not None:
1187-
f.write('"%s" -> "%s" [label="%s"]\n' %
1188-
(dist.name, other.name, label))
1161+
f.write('"%s" -> "%s" [label="%s"]\n' % (dist.name, other.name, label))
11891162
else:
11901163
f.write('"%s" -> "%s"\n' % (dist.name, other.name))
11911164
if not skip_disconnected and len(disconnected) > 0:
@@ -1225,8 +1198,7 @@ def topological_sort(self):
12251198
# Remove from the adjacency list of others
12261199
for k, v in alist.items():
12271200
alist[k] = [(d, r) for d, r in v if d not in to_remove]
1228-
logger.debug('Moving to result: %s',
1229-
['%s (%s)' % (d.name, d.version) for d in to_remove])
1201+
logger.debug('Moving to result: %s', ['%s (%s)' % (d.name, d.version) for d in to_remove])
12301202
result.extend(to_remove)
12311203
return result, list(alist.keys())
12321204

@@ -1261,15 +1233,13 @@ def make_graph(dists, scheme='default'):
12611233

12621234
# now make the edges
12631235
for dist in dists:
1264-
requires = (dist.run_requires | dist.meta_requires
1265-
| dist.build_requires | dist.dev_requires)
1236+
requires = (dist.run_requires | dist.meta_requires | dist.build_requires | dist.dev_requires)
12661237
for req in requires:
12671238
try:
12681239
matcher = scheme.matcher(req)
12691240
except UnsupportedVersionError:
12701241
# XXX compat-mode if cannot read the version
1271-
logger.warning('could not read version %r - using name only',
1272-
req)
1242+
logger.warning('could not read version %r - using name only', req)
12731243
name = req.split()[0]
12741244
matcher = scheme.matcher(name)
12751245

0 commit comments

Comments
 (0)