-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement pep 503 data-requires-python #3877
Changes from all commits
c210198
dbcefb7
86b80cc
f7373a4
17d830f
4c31a55
1d10fca
d4e22ea
bfd8794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import absolute_import | ||
import logging | ||
import sys | ||
|
||
from pip._vendor.packaging import specifiers | ||
from pip._vendor.packaging import version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def check_requires_python(requires_python): | ||
""" | ||
Check if the python version in use match the `requires_python` specifier. | ||
|
||
Returns `True` if the version of python in use matches the requirement. | ||
Returns `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 | ||
return True | ||
requires_python_specifier = specifiers.SpecifierSet(requires_python) | ||
|
||
# We only use major.minor.micro | ||
python_version = version.parse('.'.join(map(str, sys.version_info[:3]))) | ||
return python_version in requires_python_specifier |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html><head><title>Links for fakepackage</title><meta name="api-version" value="2" /></head><body><h1>Links for fakepackage</h1> | ||
<a data-requires-python='' href="/fakepackage-1.0.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-1.0.0.tar.gz</a><br/> | ||
<a data-requires-python='<2.7' href="/fakepackage-2.6.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-2.6.0.tar.gz</a><br/> | ||
<a data-requires-python='>=2.7,<3' href="/fakepackage-2.7.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-2.7.0.tar.gz</a><br/> | ||
<a data-requires-python='>=3.3' href="/fakepackage-3.3.0.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-3.3.0.tar.gz</a><br/> | ||
<a data-requires-python='><X.y.z' href="/fakepackage-9.9.9.tar.gz#md5=00000000000000000000000000000000" rel="internal">fakepackage-9.9.9.tar.gz</a><br/> | ||
</body></html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import pytest | ||
import sys | ||
|
||
import pip.wheel | ||
import pip.pep425tags | ||
|
@@ -365,6 +366,34 @@ def test_finder_only_installs_stable_releases(data): | |
assert link.url == "https://foo/bar-1.0.tar.gz" | ||
|
||
|
||
def test_finder_only_installs_data_require(data): | ||
""" | ||
Test whether the PackageFinder understand data-python-requires | ||
|
||
This can optionally be exposed by a simple-repository to tell which | ||
distribution are compatible with which version of Python by adding a | ||
data-python-require to the anchor links. | ||
|
||
See pep 503 for more informations. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for empty docstring ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, likely did not commit the description of the tests. |
||
|
||
# using a local index (that has pre & dev releases) | ||
finder = PackageFinder([], | ||
[data.index_url("datarequire")], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if it would not be clearer to create the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to do that, but it appeared to be extremely painful to figure out how to get the |
||
session=PipSession()) | ||
links = finder.find_all_candidates("fakepackage") | ||
|
||
expected = ['1.0.0', '9.9.9'] | ||
if sys.version_info < (2, 7): | ||
expected.append('2.6.0') | ||
elif (2, 7) < sys.version_info < (3,): | ||
expected.append('2.7.0') | ||
elif sys.version_info > (3, 3): | ||
expected.append('3.3.0') | ||
|
||
assert set([str(v.version) for v in links]) == set(expected) | ||
|
||
|
||
def test_finder_installs_pre_releases(data): | ||
""" | ||
Test PackageFinder finds pre-releases if asked to. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the
unescape
here since we are already dealing with html hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.