From e8afc73f9a6cf498a010acb6b644375ae954dcda Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sun, 2 Aug 2020 22:05:36 +0200 Subject: [PATCH] PEP 508 parsing: handle "== V.*" correctly --- poetry/core/packages/__init__.py | 2 +- tests/packages/test_main.py | 18 ++++++++++++++++++ tests/semver/test_parse_constraint.py | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/poetry/core/packages/__init__.py b/poetry/core/packages/__init__.py index 16854c530..7c1c05f61 100644 --- a/poetry/core/packages/__init__.py +++ b/poetry/core/packages/__init__.py @@ -165,7 +165,7 @@ def dependency_from_pep_508( ands = [] for op, version in or_: # Expand python version - if op == "==": + if op == "==" and "*" not in version: version = "~" + version op = "" elif op == "!=": diff --git a/tests/packages/test_main.py b/tests/packages/test_main.py index 34cd954ef..3df41fefd 100644 --- a/tests/packages/test_main.py +++ b/tests/packages/test_main.py @@ -236,3 +236,21 @@ def test_dependency_from_pep_508_with_python_full_version(): 'python_version >= "2.7" and python_version < "2.8" ' 'or python_full_version >= "3.4" and python_full_version < "3.5.4"' ) + + +def test_dependency_from_pep_508_with_python_full_version_pep440_compatible_release_astrix(): + name = 'pathlib2 ; python_version == "3.4.*" or python_version < "3"' + dep = dependency_from_pep_508(name) + + assert dep.name == "pathlib2" + assert str(dep.constraint) == "*" + assert dep.python_versions == "==3.4.* || <3" + + +def test_dependency_from_pep_508_with_python_full_version_pep440_compatible_release_tilde(): + name = 'pathlib2 ; python_version ~= "3.4" or python_version < "3"' + dep = dependency_from_pep_508(name) + + assert dep.name == "pathlib2" + assert str(dep.constraint) == "*" + assert dep.python_versions == "~=3.4 || <3" diff --git a/tests/semver/test_parse_constraint.py b/tests/semver/test_parse_constraint.py index b628f94a5..f70c5741e 100644 --- a/tests/semver/test_parse_constraint.py +++ b/tests/semver/test_parse_constraint.py @@ -10,6 +10,10 @@ "constraint,version", [ ("~=3.8", VersionRange(min=Version(3, 8), max=Version(4, 0), include_min=True)), + ( + "== 3.8.*", + VersionRange(min=Version(3, 8), max=Version(3, 9, 0), include_min=True), + ), ( "~= 3.8", VersionRange(min=Version(3, 8), max=Version(4, 0), include_min=True),