Skip to content

Commit

Permalink
solver: improve verbose output for dependencies with extras
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Feb 11, 2024
1 parent 4bd4587 commit db061c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/mixology/incompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ def _terse(self, term: Term, allow_every: bool = False) -> str:

if term.dependency.source_type:
return str(term.dependency)
return f"{term.dependency.pretty_name} ({term.dependency.pretty_constraint})"
pretty_name = term.dependency.complete_pretty_name
return f"{pretty_name} ({term.dependency.pretty_constraint})"

def _single_term_where(self, callable: Callable[[Term], bool]) -> Term | None:
found = None
Expand Down
50 changes: 50 additions & 0 deletions tests/mixology/test_incompatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import pytest

from poetry.core.packages.dependency import Dependency
from poetry.core.packages.url_dependency import URLDependency

from poetry.mixology.incompatibility import Incompatibility
from poetry.mixology.incompatibility_cause import DependencyCause
from poetry.mixology.term import Term


def get_url_dependency(name: str, url: str, version: str) -> URLDependency:
dependency = URLDependency(name, url)
dependency.constraint = version # type: ignore[assignment]
return dependency


@pytest.mark.parametrize(
("dependency1", "dependency2", "expected"),
[
(
Dependency("foo", "1.0"),
Dependency("bar", "2.0"),
"foo (1.0) depends on bar (2.0)",
),
(
Dependency("foo", "1.0"),
Dependency("bar", "^1.0"),
"foo (1.0) depends on bar (^1.0)",
),
(
Dependency("foo", "1.0"),
get_url_dependency("bar", "https://example.com/bar.whl", "1.1"),
"foo (1.0) depends on bar (1.1) @ https://example.com/bar.whl",
),
(
Dependency("foo", "1.0", extras=["bar"]),
Dependency("foo", "1.0"),
"foo[bar] (1.0) depends on foo (1.0)",
),
],
)
def test_str_dependency_cause(
dependency1: Dependency, dependency2: Dependency, expected: str
) -> None:
incompatibility = Incompatibility(
[Term(dependency1, True), Term(dependency2, False)], DependencyCause()
)
assert str(incompatibility) == expected

0 comments on commit db061c8

Please sign in to comment.