Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("<=", ">"):
Expand Down Expand Up @@ -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"):
Expand Down
20 changes: 7 additions & 13 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*")
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/packages/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"'
)
6 changes: 4 additions & 2 deletions tests/packages/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
10 changes: 10 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
(
Expand Down Expand Up @@ -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"),
[
Expand Down