Skip to content

Commit 6153498

Browse files
authored
Use version comparison logic for python_full_version. (#187)
1 parent 98b9b89 commit 6153498

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

distlib/markers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
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:
@@ -77,11 +81,11 @@ def evaluate(self, expr, context):
7781

7882
lhs = self.evaluate(elhs, context)
7983
rhs = self.evaluate(erhs, context)
80-
if ((elhs == 'python_version' or erhs == 'python_version') and
84+
if ((_is_version_marker(elhs) or _is_version_marker(erhs)) and
8185
op in ('<', '<=', '>', '>=', '===', '==', '!=', '~=')):
8286
lhs = NV(lhs)
8387
rhs = NV(rhs)
84-
elif elhs == 'python_version' and op in ('in', 'not in'):
88+
elif _is_version_marker(elhs) and op in ('in', 'not in'):
8589
lhs = NV(lhs)
8690
rhs = _get_versions(rhs)
8791
result = self.operations[op](lhs, rhs)

tests/test_markers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def test_interpret(self):
7878
self.assertTrue(interpret(
7979
"'buuuu' not in os_name and '%s' in os_name" % os_name))
8080

81+
# normalized version comparison correctness
82+
self.assertTrue(interpret('python_version > "5.0"', {'python_version': '10.0'}))
83+
self.assertTrue(interpret('python_version == "5.0"', {'python_version': '5.0'}))
84+
self.assertTrue(interpret('python_version < "5.0"', {'python_version': '5.0b0'}))
85+
self.assertTrue(interpret('python_full_version > "5.0"', {'python_full_version': '10.0'}))
86+
8187
# execution context
8288
self.assertTrue(interpret('python_version == "0.1"',
8389
{'python_version': '0.1'}))

0 commit comments

Comments
 (0)