Skip to content

Commit

Permalink
remove marker.constraint_string
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and radoering committed Jul 31, 2022
1 parent 2beb1b6 commit 7efc33e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
16 changes: 4 additions & 12 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def __init__(
self._constraint: BaseConstraint | VersionConstraint
self._parser: Callable[[str], BaseConstraint | VersionConstraint]
self._name = ALIASES.get(name, name)
self._constraint_string = str(constraint)
constraint_string = str(constraint)

# Extract operator and value
m = self._CONSTRAINT_RE.match(self._constraint_string)
m = self._CONSTRAINT_RE.match(constraint_string)
if m is None:
raise ValueError(f"Invalid marker '{self._constraint_string}'")
raise ValueError(f"Invalid marker '{constraint_string}'")

self._operator = m.group(1)
if self._operator is None:
Expand Down Expand Up @@ -227,11 +227,10 @@ def __init__(

self._constraint = self._parser(glue.join(versions))
else:
self._constraint = self._parser(self._constraint_string)
self._constraint = self._parser(constraint_string)
else:
# if we have a in/not in operator we split the constraint
# into a union/multi-constraint of single constraint
constraint_string = self._constraint_string
if self._operator in {"in", "not in"}:
op, glue = ("==", " || ") if self._operator == "in" else ("!=", ", ")
values = re.split("[ ,]+", self._value)
Expand All @@ -243,13 +242,6 @@ def __init__(
def name(self) -> str:
return self._name

@property
def constraint_string(self) -> str:
if self._operator in {"in", "not in"}:
return f"{self._operator} {self._value}"

return self._constraint_string

@property
def constraint(self) -> BaseConstraint | VersionConstraint:
return self._constraint
Expand Down
14 changes: 1 addition & 13 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,24 @@ def test_single_marker() -> None:

assert isinstance(m, SingleMarker)
assert m.name == "sys_platform"
assert m.constraint_string == "==darwin"
assert str(m.constraint) == "darwin"

m = parse_marker('python_version in "2.7, 3.0, 3.1"')

assert isinstance(m, SingleMarker)
assert m.name == "python_version"
assert m.constraint_string == "in 2.7, 3.0, 3.1"
assert str(m.constraint) == ">=2.7.0,<2.8.0 || >=3.0.0,<3.2.0"

m = parse_marker('"2.7" in python_version')

assert isinstance(m, SingleMarker)
assert m.name == "python_version"
assert m.constraint_string == "in 2.7"
assert str(m.constraint) == ">=2.7.0,<2.8.0"

m = parse_marker('python_version not in "2.7, 3.0, 3.1"')

assert isinstance(m, SingleMarker)
assert m.name == "python_version"
assert m.constraint_string == "not in 2.7, 3.0, 3.1"
assert str(m.constraint) == "<2.7.0 || >=2.8.0,<3.0.0 || >=3.2.0"

m = parse_marker(
Expand All @@ -54,10 +51,6 @@ def test_single_marker() -> None:

assert isinstance(m, SingleMarker)
assert m.name == "platform_machine"
assert (
m.constraint_string
== "in x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32 WIN32"
)
assert (
str(m.constraint)
== "x86_64 || X86_64 || aarch64 || AARCH64 || ppc64le || PPC64LE || amd64 ||"
Expand All @@ -71,11 +64,6 @@ def test_single_marker() -> None:

assert isinstance(m, SingleMarker)
assert m.name == "platform_machine"
assert (
m.constraint_string
== "not in x86_64 X86_64 aarch64 AARCH64 ppc64le PPC64LE amd64 AMD64 win32"
" WIN32"
)
assert (
str(m.constraint)
== "!=x86_64, !=X86_64, !=aarch64, !=AARCH64, !=ppc64le, !=PPC64LE, !=amd64,"
Expand Down

0 comments on commit 7efc33e

Please sign in to comment.