Skip to content

Commit

Permalink
Fix #72: Add support for python_implementation marker
Browse files Browse the repository at this point in the history
This is legacy from setuptools, supported from 0.7 to 20.1.1
(inclusive).
  • Loading branch information
gsnedders committed Apr 23, 2016
1 parent b6b4994 commit 3f22589
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ class Value(Node):
L("platform.version") | # PEP-345
L("platform.machine") | # PEP-345
L("platform.python_implementation") | # PEP-345
L("python_implementation") | # undocumented setuptools legacy
L("extra")
)
VARIABLE.setParseAction(lambda s, l, t: Variable(t[0].replace('.', '_')))
ALIASES = {
'python_implementation': 'platform_python_implementation'
}
VARIABLE.setParseAction(lambda s, l, t:
Variable(ALIASES.get(t[0], t[0].replace('.', '_'))))

VERSION_CMP = (
L("===") |
Expand Down
22 changes: 22 additions & 0 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"platform.python_implementation",
]

SETUPTOOLS_VARIABLES = [
"python_implementation",
]

OPERATORS = [
"===", "==", ">=", "<=", "!=", "~=", ">", "<", "in", "not in",
]
Expand Down Expand Up @@ -346,3 +350,21 @@ def test_evaluate_pep345_markers(self, marker_string, environment,
expected):
args = [] if environment is None else [environment]
assert Marker(marker_string).evaluate(*args) == expected

@pytest.mark.parametrize(
"marker_string",
[
"{0} {1} {2!r}".format(*i)
for i in itertools.product(SETUPTOOLS_VARIABLES, OPERATORS, VALUES)
] + [
"{2!r} {1} {0}".format(*i)
for i in itertools.product(SETUPTOOLS_VARIABLES, OPERATORS, VALUES)
],
)
def test_parses_setuptools_legacy_valid(self, marker_string):
Marker(marker_string)

def test_evaluate_setuptools_legacy_markers(self):
marker_string = "python_implementation=='Jython'"
args = [{"platform_python_implementation": "CPython"}]
assert Marker(marker_string).evaluate(*args) is False

0 comments on commit 3f22589

Please sign in to comment.