Skip to content

Commit e08eb2e

Browse files
Upgrade distlib to 0.3.7
1 parent 9f213bf commit e08eb2e

File tree

10 files changed

+64
-39
lines changed

10 files changed

+64
-39
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.7

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.6'
9+
__version__ = '0.3.7'
1010

1111
class DistlibException(Exception):
1212
pass

src/pip/_vendor/distlib/database.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,15 +903,18 @@ def parse_requires_data(data):
903903
lines = data.splitlines()
904904
for line in lines:
905905
line = line.strip()
906-
if line.startswith('['):
906+
# sectioned files have bare newlines (separating sections)
907+
if not line: # pragma: no cover
908+
continue
909+
if line.startswith('['): # pragma: no cover
907910
logger.warning('Unexpected line: quitting requirement scan: %r',
908911
line)
909912
break
910913
r = parse_requirement(line)
911-
if not r:
914+
if not r: # pragma: no cover
912915
logger.warning('Not recognised as a requirement: %r', line)
913916
continue
914-
if r.extras:
917+
if r.extras: # pragma: no cover
915918
logger.warning('extra requirements in requires.txt are '
916919
'not supported')
917920
if not r.constraints:

src/pip/_vendor/distlib/manifest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
_PYTHON_VERSION = sys.version_info[:2]
3636

3737
class Manifest(object):
38-
"""A list of files built by on exploring the filesystem and filtered by
39-
applying various patterns to what we find there.
38+
"""
39+
A list of files built by exploring the filesystem and filtered by applying various
40+
patterns to what we find there.
4041
"""
4142

4243
def __init__(self, base=None):

src/pip/_vendor/distlib/markers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@
2424
__all__ = ['interpret']
2525

2626
_VERSION_PATTERN = re.compile(r'((\d+(\.\d+)*\w*)|\'(\d+(\.\d+)*\w*)\'|\"(\d+(\.\d+)*\w*)\")')
27+
_VERSION_MARKERS = {'python_version', 'python_full_version'}
28+
29+
def _is_version_marker(s):
30+
return isinstance(s, string_types) and s in _VERSION_MARKERS
2731

2832
def _is_literal(o):
2933
if not isinstance(o, string_types) or not o:
3034
return False
3135
return o[0] in '\'"'
3236

3337
def _get_versions(s):
34-
result = []
35-
for m in _VERSION_PATTERN.finditer(s):
36-
result.append(NV(m.groups()[0]))
37-
return set(result)
38+
return {NV(m.groups()[0]) for m in _VERSION_PATTERN.finditer(s)}
3839

3940
class Evaluator(object):
4041
"""
41-
This class is used to evaluate marker expessions.
42+
This class is used to evaluate marker expressions.
4243
"""
4344

4445
operations = {
@@ -80,11 +81,11 @@ def evaluate(self, expr, context):
8081

8182
lhs = self.evaluate(elhs, context)
8283
rhs = self.evaluate(erhs, context)
83-
if ((elhs == 'python_version' or erhs == 'python_version') and
84+
if ((_is_version_marker(elhs) or _is_version_marker(erhs)) and
8485
op in ('<', '<=', '>', '>=', '===', '==', '!=', '~=')):
8586
lhs = NV(lhs)
8687
rhs = NV(rhs)
87-
elif elhs == 'python_version' and op in ('in', 'not in'):
88+
elif _is_version_marker(elhs) and op in ('in', 'not in'):
8889
lhs = NV(lhs)
8990
rhs = _get_versions(rhs)
9091
result = self.operations[op](lhs, rhs)

src/pip/_vendor/distlib/metadata.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,9 @@ def _version2fieldlist(version):
136136
def _best_version(fields):
137137
"""Detect the best version depending on the fields used."""
138138
def _has_marker(keys, markers):
139-
for marker in markers:
140-
if marker in keys:
141-
return True
142-
return False
143-
144-
keys = []
145-
for key, value in fields.items():
146-
if value in ([], 'UNKNOWN', None):
147-
continue
148-
keys.append(key)
139+
return any(marker in keys for marker in markers)
149140

141+
keys = [key for key, value in fields.items() if value not in ([], 'UNKNOWN', None)]
150142
possible_versions = ['1.0', '1.1', '1.2', '1.3', '2.1', '2.2'] # 2.0 removed
151143

152144
# first let's try to see if a field is not part of one of the version

src/pip/_vendor/distlib/scripts.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ def _get_shebang(self, encoding, post_interp=b'', options=None):
168168
executable = os.path.join(sysconfig.get_path('scripts'),
169169
'python%s' % sysconfig.get_config_var('EXE'))
170170
else: # pragma: no cover
171-
executable = os.path.join(
172-
sysconfig.get_config_var('BINDIR'),
173-
'python%s%s' % (sysconfig.get_config_var('VERSION'),
174-
sysconfig.get_config_var('EXE')))
175-
if not os.path.isfile(executable):
171+
if os.name == 'nt':
176172
# for Python builds from source on Windows, no Python executables with
177173
# a version suffix are created, so we use python.exe
178174
executable = os.path.join(sysconfig.get_config_var('BINDIR'),
179175
'python%s' % (sysconfig.get_config_var('EXE')))
176+
else:
177+
executable = os.path.join(
178+
sysconfig.get_config_var('BINDIR'),
179+
'python%s%s' % (sysconfig.get_config_var('VERSION'),
180+
sysconfig.get_config_var('EXE')))
180181
if options:
181182
executable = self._get_alternate_executable(executable, options)
182183

src/pip/_vendor/distlib/util.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def __eq__(self, other):
707707
__hash__ = object.__hash__
708708

709709

710-
ENTRY_RE = re.compile(r'''(?P<name>(\w|[-.+])+)
710+
ENTRY_RE = re.compile(r'''(?P<name>([^\[]\S*))
711711
\s*=\s*(?P<callable>(\w+)([:\.]\w+)*)
712712
\s*(\[\s*(?P<flags>[\w-]+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])?
713713
''', re.VERBOSE)
@@ -1249,6 +1249,19 @@ def check_path(path):
12491249
for tarinfo in archive.getmembers():
12501250
if not isinstance(tarinfo.name, text_type):
12511251
tarinfo.name = tarinfo.name.decode('utf-8')
1252+
1253+
# Limit extraction of dangerous items, if this Python
1254+
# allows it easily. If not, just trust the input.
1255+
# See: https://docs.python.org/3/library/tarfile.html#extraction-filters
1256+
def extraction_filter(member, path):
1257+
"""Run tarfile.tar_filter, but raise the expected ValueError"""
1258+
# This is only called if the current Python has tarfile filters
1259+
try:
1260+
return tarfile.tar_filter(member, path)
1261+
except tarfile.FilterError as exc:
1262+
raise ValueError(str(exc))
1263+
archive.extraction_filter = extraction_filter
1264+
12521265
archive.extractall(dest_dir)
12531266

12541267
finally:
@@ -1435,7 +1448,7 @@ def connect(self):
14351448
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
14361449
if hasattr(ssl, 'OP_NO_SSLv2'):
14371450
context.options |= ssl.OP_NO_SSLv2
1438-
if self.cert_file:
1451+
if getattr(self, 'cert_file', None):
14391452
context.load_cert_chain(self.cert_file, self.key_file)
14401453
kwargs = {}
14411454
if self.ca_certs:
@@ -1908,9 +1921,13 @@ def get_host_platform():
19081921
if m:
19091922
release = m.group()
19101923
elif osname[:6] == 'darwin':
1911-
import _osx_support, distutils.sysconfig
1924+
import _osx_support
1925+
try:
1926+
from distutils import sysconfig
1927+
except ImportError:
1928+
import sysconfig
19121929
osname, release, machine = _osx_support.get_platform_osx(
1913-
distutils.sysconfig.get_config_vars(),
1930+
sysconfig.get_config_vars(),
19141931
osname, release, machine)
19151932

19161933
return '%s-%s-%s' % (osname, release, machine)

src/pip/_vendor/distlib/version.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def __str__(self):
176176
return self._string
177177

178178

179-
PEP440_VERSION_RE = re.compile(r'^v?(\d+!)?(\d+(\.\d+)*)((a|b|c|rc)(\d+))?'
180-
r'(\.(post)(\d+))?(\.(dev)(\d+))?'
181-
r'(\+([a-zA-Z\d]+(\.[a-zA-Z\d]+)?))?$')
179+
PEP440_VERSION_RE = re.compile(r'^v?(\d+!)?(\d+(\.\d+)*)((a|alpha|b|beta|c|rc|pre|preview)(\d+)?)?'
180+
r'(\.(post|r|rev)(\d+)?)?([._-]?(dev)(\d+)?)?'
181+
r'(\+([a-zA-Z\d]+(\.[a-zA-Z\d]+)?))?$', re.I)
182182

183183

184184
def _pep_440_key(s):
@@ -202,15 +202,24 @@ def _pep_440_key(s):
202202
if pre == (None, None):
203203
pre = ()
204204
else:
205-
pre = pre[0], int(pre[1])
205+
if pre[1] is None:
206+
pre = pre[0], 0
207+
else:
208+
pre = pre[0], int(pre[1])
206209
if post == (None, None):
207210
post = ()
208211
else:
209-
post = post[0], int(post[1])
212+
if post[1] is None:
213+
post = post[0], 0
214+
else:
215+
post = post[0], int(post[1])
210216
if dev == (None, None):
211217
dev = ()
212218
else:
213-
dev = dev[0], int(dev[1])
219+
if dev[1] is None:
220+
dev = dev[0], 0
221+
else:
222+
dev = dev[0], int(dev[1])
214223
if local is None:
215224
local = ()
216225
else:

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CacheControl==0.13.1 # Make sure to update the license in pyproject.toml for this.
22
colorama==0.4.6
3-
distlib==0.3.6
3+
distlib==0.3.7
44
distro==1.8.0
55
msgpack==1.0.5
66
packaging==21.3

0 commit comments

Comments
 (0)