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
This commit is contained in:
Matthias Bussonnier 2016-07-27 12:15:24 -07:00
parent 4c31a55f63
commit 1d10fca6fc
2 changed files with 17 additions and 13 deletions

View File

@ -33,6 +33,7 @@ from pip.pep425tags import supported_tags
from pip._vendor import html5lib, requests, six
from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging import specifiers
from pip._vendor.requests.exceptions import SSLError
from pip._vendor.distlib.compat import unescape
@ -642,8 +643,12 @@ class PackageFinder(object):
self._log_skipped_link(
link, 'Python version is incorrect')
return
try:
support_this_python = check_requires_python(link.requires_python)
except specifiers.InvalidSpecifier:
support_this_python = True
if not check_requires_python(link.requires_python):
if not support_this_python:
logger.debug("The package %s is incompatible with the python"
"version in use. Acceptable python versions are:%s",
link, link.requires_python)
@ -836,7 +841,7 @@ class HTMLPage(object):
url = self.clean_link(
urllib_parse.urljoin(self.base_url, href)
)
pyrequire = anchor.get('data-requires-python')
pyrequire = unescape(anchor.get('data-requires-python'))
yield Link(url, self, requires_python=pyrequire)
_clean_re = re.compile(r'[^a-z0-9$&+,/:;=?@.#%_\\|-]', re.I)
@ -857,13 +862,11 @@ class Link(object):
url:
url of the resource pointed to (href of the link)
comes_form:
comes_from:
<Not sure>
requires_python:
String containing the `Requires-Python` metadata field, specified
in PEP 345. This is to understand pep 503. The `requires_python`
string will be unescaped as pep 503 requires `<` and `>` to be
escaped, then stored under the `requires_python` attribute.
in PEP 345.
"""
# url can be a UNC windows share
@ -875,7 +878,7 @@ class Link(object):
if not requires_python:
self.requires_python = None
else:
self.requires_python = unescape(requires_python)
self.requires_python = requires_python
def __str__(self):
if self.requires_python:

View File

@ -7,13 +7,15 @@ from pip._vendor.packaging import version
logger = logging.getLogger(__name__)
def check_requires_python(requires_python):
"""
Check if the python version in used match the `requires_python` specifier passed.
Check if the python version in used match the `requires_python` specifier.
Return `True` if the version of python in use matches the requirement.
Return `False` if the version of python in use does not matches the requirement.
Raises an InvalidSpecifier if `requires_python` have an invalid format.
Return `False` if the version of python in use does not matches the
requirement. Raises an InvalidSpecifier if `requires_python` have an
invalid format.
"""
if requires_python is None:
# The package provides no information
@ -23,10 +25,9 @@ def check_requires_python(requires_python):
except specifiers.InvalidSpecifier as e:
logger.debug(
"Package %s has an invalid Requires-Python entry - %s" % (
requires_python, e))
raise specifiers.InvalidSpecifier(*e.args)
requires_python, e))
raise
# We only use major.minor.micro
python_version = version.parse('.'.join(map(str, sys.version_info[:3])))
return python_version in requires_python_specifier