Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python_full_version marker conversion to constraint #86

Merged
merged 1 commit into from
Sep 25, 2020
Merged
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
2 changes: 1 addition & 1 deletion poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def create_nested_marker(name, constraint):
def get_python_constraint_from_marker(
marker,
): # type: (BaseMarker) -> VersionConstraint
python_marker = marker.only("python_version")
python_marker = marker.only("python_version", "python_full_version")
if python_marker.is_any():
return VersionRange()

Expand Down
22 changes: 11 additions & 11 deletions poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def without_extras(self): # type: () -> BaseMarker
def exclude(self, marker_name): # type: (str) -> BaseMarker
raise NotImplementedError()

def only(self, marker_name): # type: (str) -> BaseMarker
def only(self, *marker_names): # type: (str) -> BaseMarker
raise NotImplementedError()

def invert(self): # type: () -> BaseMarker
Expand Down Expand Up @@ -97,7 +97,7 @@ def without_extras(self):
def exclude(self, marker_name): # type: (str) -> AnyMarker
return self

def only(self, marker_name): # type: (str) -> AnyMarker
def only(self, *marker_names): # type: (str) -> AnyMarker
return self

def invert(self): # type: () -> EmptyMarker
Expand Down Expand Up @@ -141,7 +141,7 @@ def without_extras(self):
def exclude(self, marker_name): # type: (str) -> EmptyMarker
return self

def only(self, marker_name): # type: (str) -> EmptyMarker
def only(self, *marker_names): # type: (str) -> EmptyMarker
return self

def invert(self): # type: () -> AnyMarker
Expand Down Expand Up @@ -287,8 +287,8 @@ def exclude(self, marker_name): # type: (str) -> BaseMarker

return self

def only(self, marker_name): # type: (str) -> BaseMarker
if self.name != marker_name:
def only(self, *marker_names): # type: (str) -> BaseMarker
if self.name not in marker_names:
return EmptyMarker()

return self
Expand Down Expand Up @@ -464,15 +464,15 @@ def exclude(self, marker_name): # type: (str) -> BaseMarker

return self.of(*new_markers)

def only(self, marker_name): # type: (str) -> BaseMarker
def only(self, *marker_names): # type: (str) -> BaseMarker
new_markers = []

for m in self._markers:
if isinstance(m, SingleMarker) and m.name != marker_name:
if isinstance(m, SingleMarker) and m.name not in marker_names:
# The marker is not relevant since it's not one we want
continue

marker = m.only(marker_name)
marker = m.only(*marker_names)

if not marker.is_empty():
new_markers.append(marker)
Expand Down Expand Up @@ -628,15 +628,15 @@ def exclude(self, marker_name): # type: (str) -> BaseMarker

return self.of(*new_markers)

def only(self, marker_name): # type: (str) -> BaseMarker
def only(self, *marker_names): # type: (str) -> BaseMarker
new_markers = []

for m in self._markers:
if isinstance(m, SingleMarker) and m.name != marker_name:
if isinstance(m, SingleMarker) and m.name not in marker_names:
# The marker is not relevant since it's not one we want
continue

marker = m.only(marker_name)
marker = m.only(*marker_names)

if not marker.is_empty():
new_markers.append(marker)
Expand Down
20 changes: 20 additions & 0 deletions tests/packages/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import pytest

from poetry.core.packages.utils.utils import convert_markers
from poetry.core.packages.utils.utils import get_python_constraint_from_marker
from poetry.core.semver import parse_constraint
from poetry.core.version.markers import parse_marker


Expand All @@ -21,3 +25,19 @@ def test_convert_markers():
converted = convert_markers(marker)

assert converted["python_version"] == [[("==", "2.7")], [("==", "2.6")]]


@pytest.mark.parametrize(
["marker", "constraint"],
[
('python_version >= "3.6" and python_full_version < "4.0"', ">=3.6, <4.0"),
(
'python_full_version >= "3.6.1" and python_full_version < "4.0.0"',
">=3.6.1, <4.0.0",
),
],
)
def test_get_python_constraint_from_marker(marker, constraint):
marker = parse_marker(marker)
constraint = parse_constraint(constraint)
assert constraint == get_python_constraint_from_marker(marker)
19 changes: 12 additions & 7 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,38 +572,43 @@ def test_exclude(marker, excluded, expected):
@pytest.mark.parametrize(
"marker, only, expected",
[
('python_version >= "3.6"', "python_version", 'python_version >= "3.6"'),
('python_version >= "3.6"', ["python_version"], 'python_version >= "3.6"'),
(
'python_version >= "3.6" and extra == "foo"',
"python_version",
["python_version"],
'python_version >= "3.6"',
),
(
'python_version >= "3.6" and (extra == "foo" or extra == "bar")',
"extra",
["extra"],
'(extra == "foo" or extra == "bar")',
),
(
'python_version >= "3.6" and (extra == "foo" or extra == "bar") or implementation_name == "pypy"',
"implementation_name",
["implementation_name"],
'implementation_name == "pypy"',
),
(
'python_version >= "3.6" and extra == "foo" or implementation_name == "pypy" and extra == "bar"',
"implementation_name",
["implementation_name"],
'implementation_name == "pypy"',
),
(
'python_version >= "3.6" or extra == "foo" and implementation_name == "pypy" or extra == "bar"',
"implementation_name",
["implementation_name"],
'implementation_name == "pypy"',
),
(
'python_version >= "3.6" or extra == "foo" and implementation_name == "pypy" or extra == "bar"',
["implementation_name", "python_version"],
'python_version >= "3.6" or implementation_name == "pypy"',
),
],
)
def test_only(marker, only, expected):
m = parse_marker(marker)

assert expected == str(m.only(only))
assert expected == str(m.only(*only))


def test_union_of_a_single_marker_is_the_single_marker():
Expand Down