diff --git a/src/poetry/core/packages/utils/utils.py b/src/poetry/core/packages/utils/utils.py index 78cf9f70a..a1523ede2 100644 --- a/src/poetry/core/packages/utils/utils.py +++ b/src/poetry/core/packages/utils/utils.py @@ -368,10 +368,14 @@ def normalize_python_version_markers( # NOSONAR for op, version in or_: # Expand python version if op == "==" and "*" not in version and version.count(".") < 2: + if version.count(".") == 0: + version += ".0" version = "~" + version op = "" elif op == "!=" and "*" not in version and version.count(".") < 2: + if version.count(".") == 0: + version += ".0" version += ".*" elif op in ("<=", ">"): @@ -402,7 +406,6 @@ def normalize_python_version_markers( # NOSONAR elif op == ">": op = ">=" - if parsed_version.precision == 2: version = parsed_version.next_minor().text elif op in ("in", "not in"): diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index 768e614eb..b8715441b 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -49,16 +49,6 @@ def test_to_pep_508() -> None: result = dependency.to_pep_508() assert result == "Django (>=1.23,<2.0)" - dependency = Dependency("Django", "^1.23") - dependency.python_versions = "~2.7 || ^3.6" - - result = dependency.to_pep_508() - assert ( - result == "Django (>=1.23,<2.0) ; " - 'python_version == "2.7" ' - 'or python_version >= "3.6" and python_version < "4.0"' - ) - def test_to_pep_508_wilcard() -> None: dependency = Dependency("Django", "*") @@ -136,11 +126,15 @@ def test_to_pep_508_with_excluded_versions(exclusion: str, expected: str) -> Non ("<3.5.4", 'python_full_version < "3.5.4"'), (">=3.5.4", 'python_full_version >= "3.5.4"'), ("== 3.5.4", 'python_full_version == "3.5.4"'), + (">=3,<4", 'python_version >= "3" and python_version < "4"'), + ("==3.*", 'python_version >= "3" and python_version < "4"'), + ( + "~2.7 || ^3.6", + 'python_version == "2.7" or python_version >= "3.6" and python_version < "4.0"', + ), ], ) -def test_to_pep_508_with_patch_python_version( - python_versions: str, marker: str -) -> None: +def test_to_pep_508_with_python_versions(python_versions: str, marker: str) -> None: dependency = Dependency("Django", "^1.23") dependency.python_versions = python_versions diff --git a/tests/packages/test_main.py b/tests/packages/test_main.py index b9ae56d31..58c4d6a61 100644 --- a/tests/packages/test_main.py +++ b/tests/packages/test_main.py @@ -325,7 +325,7 @@ def test_dependency_from_pep_508_should_not_produce_empty_constraints_for_correc ): name = ( 'pytest-mypy; python_implementation != "PyPy" and python_version <= "3.10" and' - ' python_version > "3"' + ' python_version >= "3"' ) dep = Dependency.create_from_pep_508(name) @@ -339,5 +339,5 @@ def test_dependency_from_pep_508_should_not_produce_empty_constraints_for_correc assert ( str(dep.marker) == 'platform_python_implementation != "PyPy" and python_version <= "3.10" and' - ' python_version > "3"' + ' python_version >= "3"' ) diff --git a/tests/packages/utils/test_utils.py b/tests/packages/utils/test_utils.py index 0215a5473..427b69819 100644 --- a/tests/packages/utils/test_utils.py +++ b/tests/packages/utils/test_utils.py @@ -177,14 +177,16 @@ def test_create_nested_marker_version_constraint( ('python_version == "3.6"', "~3.6"), ('python_version == "3.6.*"', "==3.6.*"), ('python_version == "3.6.* "', "==3.6.*"), + ('python_version == "3"', ">=3.0,<3.1"), + ('python_version == "3.*"', ">=3,<4"), # != ('python_version != "3.6"', "!=3.6.*"), ('python_version != "3.6.*"', "!=3.6.*"), ('python_version != "3.6.* "', "!=3.6.*"), # <, <=, >, >= precision 1 ('python_version < "3"', "<3"), - ('python_version <= "3"', "<3"), - ('python_version > "3"', ">=3"), + ('python_version <= "3"', "<3.1"), + ('python_version > "3"', ">=3.1"), ('python_version >= "3"', ">=3"), # <, <=, >, >= precision 2 ('python_version < "3.6"', "<3.6"), diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 74136efcc..55890f768 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -32,6 +32,9 @@ @pytest.mark.parametrize( "marker", [ + 'python_version >= "3.6" and python_version < "3.9"', + 'python_version >= "3.0" and python_version < "4.0"', + 'python_version >= "3" and python_version < "4"', 'sys_platform == "linux" or sys_platform == "win32"', 'sys_platform == "win32" or sys_platform == "linux"', ( @@ -273,6 +276,13 @@ def test_single_marker_not_in_python_intersection() -> None: assert str(intersection) == 'python_version not in "2.7, 3.0, 3.1, 3.2"' +def test_single_marker_intersect_python_version_only_major() -> None: + m = parse_marker('python_version >= "3"') + m2 = parse_marker('python_version < "4"') + intersection = m.intersect(m2) + assert str(intersection) == 'python_version >= "3" and python_version < "4"' + + @pytest.mark.parametrize( ("marker1", "marker2", "expected"), [