Skip to content
New issue

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

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

Already on GitHub? # to your account

specification: add ignore_features flag to is_same_package_as #321

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/poetry/core/packages/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ def source_subdirectory(self) -> str | None:
def features(self) -> frozenset[str]:
return self._features

def is_same_package_as(self, other: PackageSpecification) -> bool:
if other.complete_name != self.complete_name:
return False
def is_same_package_as(
self, other: PackageSpecification, *, ignore_features: bool = False
) -> bool:
if ignore_features:
if other.name != self.name:
return False
else:
if other.complete_name != self.complete_name:
return False

if self._source_type:
if self._source_type != other.source_type:
Expand Down
37 changes: 37 additions & 0 deletions tests/packages/test_specification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import pytest

from poetry.core.packages.specification import PackageSpecification


@pytest.mark.parametrize(
"spec1, spec2, expected_exact, expected_ignore_features",
[
(PackageSpecification("a"), PackageSpecification("a"), True, True),
(PackageSpecification("a"), PackageSpecification("ab"), False, False),
(
PackageSpecification("a"),
PackageSpecification("a", features=["c"]),
False,
True,
),
(
PackageSpecification("a", features=["c"]),
PackageSpecification("a", features=["c", "d"]),
False,
True,
),
],
)
def test_is_same_package_ignore_features(
spec1: PackageSpecification,
spec2: PackageSpecification,
expected_exact: bool,
expected_ignore_features: bool,
) -> None:
assert spec1.is_same_package_as(spec2) == expected_exact
assert (
spec1.is_same_package_as(spec2, ignore_features=True)
== expected_ignore_features
)