Skip to content

Commit

Permalink
specification: add ignore_features flag to is_same_package_as
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Apr 16, 2022
1 parent f405311 commit d967a22
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
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
)

0 comments on commit d967a22

Please # to comment.