Skip to content

Commit

Permalink
specification: add allow_similar flag to is_same_package_as
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Apr 11, 2022
1 parent f405311 commit f55db69
Show file tree
Hide file tree
Showing 2 changed files with 37 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, *, allow_similar: bool = False
) -> bool:
if allow_similar:
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
28 changes: 28 additions & 0 deletions tests/packages/test_specification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import pytest

from poetry.core.packages.specification import PackageSpecification


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

0 comments on commit f55db69

Please # to comment.