Skip to content

Commit 1d10fca

Browse files
committed
Fix pep-8, assume work on this Python or invalid specifiers.
move the unescape outside of Link class. reraise using raise that is available on Python 2.6
1 parent 4c31a55 commit 1d10fca

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pip/index.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pip._vendor import html5lib, requests, six
3434
from pip._vendor.packaging.version import parse as parse_version
3535
from pip._vendor.packaging.utils import canonicalize_name
36+
from pip._vendor.packaging import specifiers
3637
from pip._vendor.requests.exceptions import SSLError
3738
from pip._vendor.distlib.compat import unescape
3839

@@ -642,8 +643,12 @@ def _link_package_versions(self, link, search):
642643
self._log_skipped_link(
643644
link, 'Python version is incorrect')
644645
return
646+
try:
647+
support_this_python = check_requires_python(link.requires_python)
648+
except specifiers.InvalidSpecifier:
649+
support_this_python = True
645650

646-
if not check_requires_python(link.requires_python):
651+
if not support_this_python:
647652
logger.debug("The package %s is incompatible with the python"
648653
"version in use. Acceptable python versions are:%s",
649654
link, link.requires_python)
@@ -836,7 +841,7 @@ def links(self):
836841
url = self.clean_link(
837842
urllib_parse.urljoin(self.base_url, href)
838843
)
839-
pyrequire = anchor.get('data-requires-python')
844+
pyrequire = unescape(anchor.get('data-requires-python'))
840845
yield Link(url, self, requires_python=pyrequire)
841846

842847
_clean_re = re.compile(r'[^a-z0-9$&+,/:;=?@.#%_\\|-]', re.I)
@@ -857,13 +862,11 @@ def __init__(self, url, comes_from=None, requires_python=None):
857862
858863
url:
859864
url of the resource pointed to (href of the link)
860-
comes_form:
865+
comes_from:
861866
<Not sure>
862867
requires_python:
863868
String containing the `Requires-Python` metadata field, specified
864-
in PEP 345. This is to understand pep 503. The `requires_python`
865-
string will be unescaped as pep 503 requires `<` and `>` to be
866-
escaped, then stored under the `requires_python` attribute.
869+
in PEP 345.
867870
"""
868871

869872
# url can be a UNC windows share
@@ -875,7 +878,7 @@ def __init__(self, url, comes_from=None, requires_python=None):
875878
if not requires_python:
876879
self.requires_python = None
877880
else:
878-
self.requires_python = unescape(requires_python)
881+
self.requires_python = requires_python
879882

880883
def __str__(self):
881884
if self.requires_python:

pip/utils/packaging.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
logger = logging.getLogger(__name__)
99

10+
1011
def check_requires_python(requires_python):
1112
"""
12-
Check if the python version in used match the `requires_python` specifier passed.
13+
Check if the python version in used match the `requires_python` specifier.
1314
1415
Return `True` if the version of python in use matches the requirement.
15-
Return `False` if the version of python in use does not matches the requirement.
16-
Raises an InvalidSpecifier if `requires_python` have an invalid format.
16+
Return `False` if the version of python in use does not matches the
17+
requirement. Raises an InvalidSpecifier if `requires_python` have an
18+
invalid format.
1719
"""
1820
if requires_python is None:
1921
# The package provides no information
@@ -23,10 +25,9 @@ def check_requires_python(requires_python):
2325
except specifiers.InvalidSpecifier as e:
2426
logger.debug(
2527
"Package %s has an invalid Requires-Python entry - %s" % (
26-
requires_python, e))
27-
raise specifiers.InvalidSpecifier(*e.args)
28+
requires_python, e))
29+
raise
2830

2931
# We only use major.minor.micro
3032
python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
3133
return python_version in requires_python_specifier
32-

0 commit comments

Comments
 (0)