Skip to content

Commit

Permalink
Fix dependency markers not being copied in with_constraint()
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored and abn committed Apr 9, 2021
1 parent c8852ca commit 3d94e87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def with_constraint(

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 @@ -3,6 +3,7 @@
from poetry.core.packages import Dependency
from poetry.core.packages import Package
from poetry.core.packages import dependency_from_pep_508
from poetry.core.version.markers import parse_marker


def test_accepts():
Expand Down Expand Up @@ -224,3 +225,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

0 comments on commit 3d94e87

Please sign in to comment.