Skip to content

Commit

Permalink
Upgrade distlib to 0.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 authored and sbidoul committed Oct 20, 2024
1 parent ec5faea commit d941aa4
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 513 deletions.
1 change: 1 addition & 0 deletions news/distlib.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade distlib to 0.3.9
2 changes: 1 addition & 1 deletion src/pip/_vendor/distlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
import logging

__version__ = '0.3.8'
__version__ = '0.3.9'


class DistlibException(Exception):
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_vendor/distlib/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
return (os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn))

# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
Expand Down
90 changes: 30 additions & 60 deletions src/pip/_vendor/distlib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@
from . import DistlibException, resources
from .compat import StringIO
from .version import get_scheme, UnsupportedVersionError
from .metadata import (Metadata, METADATA_FILENAME, WHEEL_METADATA_FILENAME,
LEGACY_METADATA_FILENAME)
from .util import (parse_requirement, cached_property, parse_name_and_version,
read_exports, write_exports, CSVReader, CSVWriter)
from .metadata import (Metadata, METADATA_FILENAME, WHEEL_METADATA_FILENAME, LEGACY_METADATA_FILENAME)
from .util import (parse_requirement, cached_property, parse_name_and_version, read_exports, write_exports, CSVReader,
CSVWriter)

__all__ = [
'Distribution', 'BaseInstalledDistribution', 'InstalledDistribution',
'EggInfoDistribution', 'DistributionPath'
'Distribution', 'BaseInstalledDistribution', 'InstalledDistribution', 'EggInfoDistribution', 'DistributionPath'
]

logger = logging.getLogger(__name__)

EXPORTS_FILENAME = 'pydist-exports.json'
COMMANDS_FILENAME = 'pydist-commands.json'

DIST_FILES = ('INSTALLER', METADATA_FILENAME, 'RECORD', 'REQUESTED',
'RESOURCES', EXPORTS_FILENAME, 'SHARED')
DIST_FILES = ('INSTALLER', METADATA_FILENAME, 'RECORD', 'REQUESTED', 'RESOURCES', EXPORTS_FILENAME, 'SHARED')

DISTINFO_EXT = '.dist-info'

Expand Down Expand Up @@ -134,29 +131,21 @@ def _yield_distributions(self):
continue
try:
if self._include_dist and entry.endswith(DISTINFO_EXT):
possible_filenames = [
METADATA_FILENAME, WHEEL_METADATA_FILENAME,
LEGACY_METADATA_FILENAME
]
possible_filenames = [METADATA_FILENAME, WHEEL_METADATA_FILENAME, LEGACY_METADATA_FILENAME]
for metadata_filename in possible_filenames:
metadata_path = posixpath.join(
entry, metadata_filename)
metadata_path = posixpath.join(entry, metadata_filename)
pydist = finder.find(metadata_path)
if pydist:
break
else:
continue

with contextlib.closing(pydist.as_stream()) as stream:
metadata = Metadata(fileobj=stream,
scheme='legacy')
metadata = Metadata(fileobj=stream, scheme='legacy')
logger.debug('Found %s', r.path)
seen.add(r.path)
yield new_dist_class(r.path,
metadata=metadata,
env=self)
elif self._include_egg and entry.endswith(
('.egg-info', '.egg')):
yield new_dist_class(r.path, metadata=metadata, env=self)
elif self._include_egg and entry.endswith(('.egg-info', '.egg')):
logger.debug('Found %s', r.path)
seen.add(r.path)
yield old_dist_class(r.path, self)
Expand Down Expand Up @@ -274,8 +263,7 @@ def provides_distribution(self, name, version=None):
try:
matcher = self._scheme.matcher('%s (%s)' % (name, version))
except ValueError:
raise DistlibException('invalid name or version: %r, %r' %
(name, version))
raise DistlibException('invalid name or version: %r, %r' % (name, version))

for dist in self.get_distributions():
# We hit a problem on Travis where enum34 was installed and doesn't
Expand Down Expand Up @@ -390,10 +378,8 @@ def provides(self):
def _get_requirements(self, req_attr):
md = self.metadata
reqts = getattr(md, req_attr)
logger.debug('%s: got requirements %r from metadata: %r', self.name,
req_attr, reqts)
return set(
md.get_requirements(reqts, extras=self.extras, env=self.context))
logger.debug('%s: got requirements %r from metadata: %r', self.name, req_attr, reqts)
return set(md.get_requirements(reqts, extras=self.extras, env=self.context))

@property
def run_requires(self):
Expand Down Expand Up @@ -469,8 +455,7 @@ def __eq__(self, other):
if type(other) is not type(self):
result = False
else:
result = (self.name == other.name and self.version == other.version
and self.source_url == other.source_url)
result = (self.name == other.name and self.version == other.version and self.source_url == other.source_url)
return result

def __hash__(self):
Expand Down Expand Up @@ -561,8 +546,7 @@ def __init__(self, path, metadata=None, env=None):
if r is None:
r = finder.find(LEGACY_METADATA_FILENAME)
if r is None:
raise ValueError('no %s found in %s' %
(METADATA_FILENAME, path))
raise ValueError('no %s found in %s' % (METADATA_FILENAME, path))
with contextlib.closing(r.as_stream()) as stream:
metadata = Metadata(fileobj=stream, scheme='legacy')

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

def __repr__(self):
return '<InstalledDistribution %r %s at %r>' % (
self.name, self.version, self.path)
return '<InstalledDistribution %r %s at %r>' % (self.name, self.version, self.path)

def __str__(self):
return "%s %s" % (self.name, self.version)
Expand Down Expand Up @@ -703,8 +686,7 @@ def write_installed_files(self, paths, prefix, dry_run=False):
size = '%d' % os.path.getsize(path)
with open(path, 'rb') as fp:
hash_value = self.get_hash(fp.read())
if path.startswith(base) or (base_under_prefix
and path.startswith(prefix)):
if path.startswith(base) or (base_under_prefix and path.startswith(prefix)):
path = os.path.relpath(path, base)
writer.writerow((path, hash_value, size))

Expand Down Expand Up @@ -746,8 +728,7 @@ def check_installed_files(self):
with open(path, 'rb') as f:
actual_hash = self.get_hash(f.read(), hasher)
if actual_hash != hash_value:
mismatches.append(
(path, 'hash', hash_value, actual_hash))
mismatches.append((path, 'hash', hash_value, actual_hash))
return mismatches

@cached_property
Expand Down Expand Up @@ -829,9 +810,8 @@ def get_distinfo_file(self, path):
# it's an absolute path?
distinfo_dirname, path = path.split(os.sep)[-2:]
if distinfo_dirname != self.path.split(os.sep)[-1]:
raise DistlibException(
'dist-info file %r does not belong to the %r %s '
'distribution' % (path, self.name, self.version))
raise DistlibException('dist-info file %r does not belong to the %r %s '
'distribution' % (path, self.name, self.version))

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

def __eq__(self, other):
return (isinstance(other, InstalledDistribution)
and self.path == other.path)
return (isinstance(other, InstalledDistribution) and self.path == other.path)

# See http://docs.python.org/reference/datamodel#object.__hash__
__hash__ = object.__hash__
Expand Down Expand Up @@ -911,8 +890,7 @@ def parse_requires_data(data):
if not line: # pragma: no cover
continue
if line.startswith('['): # pragma: no cover
logger.warning(
'Unexpected line: quitting requirement scan: %r', line)
logger.warning('Unexpected line: quitting requirement scan: %r', line)
break
r = parse_requirement(line)
if not r: # pragma: no cover
Expand Down Expand Up @@ -954,13 +932,11 @@ def parse_requires_path(req_path):
else:
# FIXME handle the case where zipfile is not available
zipf = zipimport.zipimporter(path)
fileobj = StringIO(
zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
fileobj = StringIO(zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
metadata = Metadata(fileobj=fileobj, scheme='legacy')
try:
data = zipf.get_data('EGG-INFO/requires.txt')
tl_data = zipf.get_data('EGG-INFO/top_level.txt').decode(
'utf-8')
tl_data = zipf.get_data('EGG-INFO/top_level.txt').decode('utf-8')
requires = parse_requires_data(data.decode('utf-8'))
except IOError:
requires = None
Expand Down Expand Up @@ -990,8 +966,7 @@ def parse_requires_path(req_path):
return metadata

def __repr__(self):
return '<EggInfoDistribution %r %s at %r>' % (self.name, self.version,
self.path)
return '<EggInfoDistribution %r %s at %r>' % (self.name, self.version, self.path)

def __str__(self):
return "%s %s" % (self.name, self.version)
Expand Down Expand Up @@ -1083,8 +1058,7 @@ def list_distinfo_files(self, absolute=False):
yield line

def __eq__(self, other):
return (isinstance(other, EggInfoDistribution)
and self.path == other.path)
return (isinstance(other, EggInfoDistribution) and self.path == other.path)

# See http://docs.python.org/reference/datamodel#object.__hash__
__hash__ = object.__hash__
Expand Down Expand Up @@ -1184,8 +1158,7 @@ def to_dot(self, f, skip_disconnected=True):
disconnected.append(dist)
for other, label in adjs:
if label is not None:
f.write('"%s" -> "%s" [label="%s"]\n' %
(dist.name, other.name, label))
f.write('"%s" -> "%s" [label="%s"]\n' % (dist.name, other.name, label))
else:
f.write('"%s" -> "%s"\n' % (dist.name, other.name))
if not skip_disconnected and len(disconnected) > 0:
Expand Down Expand Up @@ -1225,8 +1198,7 @@ def topological_sort(self):
# Remove from the adjacency list of others
for k, v in alist.items():
alist[k] = [(d, r) for d, r in v if d not in to_remove]
logger.debug('Moving to result: %s',
['%s (%s)' % (d.name, d.version) for d in to_remove])
logger.debug('Moving to result: %s', ['%s (%s)' % (d.name, d.version) for d in to_remove])
result.extend(to_remove)
return result, list(alist.keys())

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

# now make the edges
for dist in dists:
requires = (dist.run_requires | dist.meta_requires
| dist.build_requires | dist.dev_requires)
requires = (dist.run_requires | dist.meta_requires | dist.build_requires | dist.dev_requires)
for req in requires:
try:
matcher = scheme.matcher(req)
except UnsupportedVersionError:
# XXX compat-mode if cannot read the version
logger.warning('could not read version %r - using name only',
req)
logger.warning('could not read version %r - using name only', req)
name = req.split()[0]
matcher = scheme.matcher(name)

Expand Down
Loading

0 comments on commit d941aa4

Please sign in to comment.