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

dependency: consider source_name in is_same_source_as #488

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __init__(
source_reference: str | None = None,
source_resolved_reference: str | None = None,
source_subdirectory: str | None = None,
*,
source_name: str | None = None,
) -> None:
from poetry.core.version.markers import AnyMarker

Expand Down Expand Up @@ -92,7 +94,7 @@ def __init__(

self.is_root = False
self._marker: BaseMarker = AnyMarker()
self.source_name: str | None = None
self.source_name: str | None = source_name

@property
def name(self) -> NormalizedName:
Expand Down Expand Up @@ -475,6 +477,11 @@ def create_from_pep_508(

return dep

def is_same_source_as(self, other: PackageSpecification) -> bool:
if isinstance(other, Dependency) and self.source_name != other.source_name:
return False
return super().is_same_source_as(other)

def __eq__(self, other: object) -> bool:
if not isinstance(other, Dependency):
return NotImplemented
Expand Down
21 changes: 21 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from poetry.core.constraints.version.exceptions import ParseConstraintError
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.specification import PackageSpecification
from poetry.core.version.markers import parse_marker


Expand Down Expand Up @@ -314,6 +315,26 @@ def test_create_from_pep_508_url_with_activated_extras() -> None:
assert dependency.extras == {"fred", "bar"}


@pytest.mark.parametrize(
"dependency, package_specification, expected",
[
(Dependency("a", "*"), Dependency("b", "*"), True),
(Dependency("a", "*", source_name="s"), Dependency("b", "*"), False),
(
Dependency("a", "*", source_name="s1"),
Dependency("b", "*", source_name="s2"),
False,
),
(Dependency("a", "*", source_name="s"), PackageSpecification("b"), True),
],
)
def test_is_same_source_as(
dependency: Dependency, package_specification: PackageSpecification, expected: bool
) -> None:
assert dependency.is_same_source_as(package_specification) is expected
assert package_specification.is_same_source_as(dependency) is expected


@pytest.mark.parametrize(
"dependency1, dependency2, expected",
[
Expand Down