Skip to content

Commit 9e05d2c

Browse files
authored
fix: [OSM-2189] refactor sys_platform selector (#257)
* fix: refactor system marker regex * fix: PEP508 support of multiple sys_platforms * fix: refactor sys_platform match logic
1 parent 0b99485 commit 9e05d2c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pysrc/pip_resolve.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
PYTHON_MARKER_REGEX = re.compile(r'python_version\s*('
1717
r'?P<operator>==|<=|>=|>|<)\s*[\'"]('
1818
r'?P<python_version>.+?)[\'"]')
19-
SYSTEM_MARKER_REGEX = re.compile(r'sys_platform\s*==\s*[\'"](.+)[\'"]')
19+
SYSTEM_MARKER_REGEX = re.compile(r'sys_platform\s*==\s*[\'"]([\w.-]+)[\'"]')
2020
DEPENDENCIES = 'dependencies'
2121
VERSION = 'version'
2222
NAME = 'name'
@@ -271,9 +271,10 @@ def matches_environment(requirement):
271271
sys_platform = sys.platform.lower()
272272
markers_text = get_markers_text(requirement)
273273
if markers_text and 'sys_platform' in markers_text:
274-
match = SYSTEM_MARKER_REGEX.findall(markers_text)
275-
if len(match) > 0:
276-
return match[0].lower() == sys_platform
274+
matches = SYSTEM_MARKER_REGEX.findall(markers_text)
275+
lowercase_matches = [match.lower() for match in matches]
276+
if lowercase_matches:
277+
return sys_platform.lower() in lowercase_matches
277278
return True
278279

279280

pysrc/test_pip_resolve_py3.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ def test_matches_environment(self):
5858
req.line = "futures==3.2.0; sys_platform == 'linux2'"
5959
self.assertFalse (matches_environment(req))
6060

61+
mock_sys.platform = "linux"
62+
req.line = "jinja2==3.1.4 ; sys_platform == 'darwin' or sys_platform == 'linux'"
63+
self.assertTrue(matches_environment(req))
64+
65+
mock_sys.platform = "darwin"
66+
req.line = "jinja2==3.1.4 ; sys_platform == 'darwin' or sys_platform == 'linux'"
67+
self.assertTrue(matches_environment(req))
68+
6169
# BUG: Only == operator is supported in the moment
6270
# mock_sys.platform = "linux2"
6371
# req.line = "futures==3.2.0; sys_platform != 'linux2'"

0 commit comments

Comments
 (0)