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 dependency markers not being copied in with_constraint() #162

Merged
merged 1 commit into from
Apr 9, 2021
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
3 changes: 3 additions & 0 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ def with_constraint(self, constraint: Union[str, "VersionTypes"]) -> "Dependency

new.is_root = self.is_root
new.python_versions = self.python_versions
new.transitive_python_versions = self.transitive_python_versions
new.marker = self.marker
new.transitive_marker = self.transitive_marker

for in_extra in self.in_extras:
new.in_extras.append(in_extra)
Expand Down
33 changes: 33 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.version.markers import parse_marker


def test_accepts():
Expand Down Expand Up @@ -225,3 +226,35 @@ def test_complete_name():
def test_dependency_string_representation(name, constraint, extras, expected):
dependency = Dependency(name=name, constraint=constraint, extras=extras)
assert str(dependency) == expected


def test_with_constraint():
dependency = Dependency(
"foo",
"^1.2.3",
optional=True,
category="dev",
allows_prereleases=True,
extras=["bar", "baz"],
)
dependency.marker = parse_marker(
'python_version >= "3.6" and python_version < "4.0"'
)
dependency.transitive_marker = parse_marker(
'python_version >= "3.7" and python_version < "4.0"'
)
dependency.python_versions = "^3.6"
dependency.transitive_python_versions = "^3.7"

new = dependency.with_constraint("^1.2.6")

assert new.name == dependency.name
assert str(new.constraint) == ">=1.2.6,<2.0.0"
assert new.is_optional()
assert new.category == "dev"
assert new.allows_prereleases()
assert set(new.extras) == {"bar", "baz"}
assert new.marker == dependency.marker
assert new.transitive_marker == dependency.transitive_marker
assert new.python_constraint == dependency.python_constraint
assert new.transitive_python_constraint == dependency.transitive_python_constraint