Skip to content

Commit

Permalink
fix: poetry show --top-level works with extras
Browse files Browse the repository at this point in the history
  • Loading branch information
ralbertazzi committed Jun 7, 2023
1 parent a9ac06f commit 15d78fa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ def _display_packages_information(
name = locked.pretty_name
install_marker = ""

if show_top_level and not any(
locked.is_same_package_as(r) for r in requires
):
if show_top_level and not any(locked.satisfies(r) for r in requires):
continue

if locked not in required_locked_packages:
Expand Down
69 changes: 69 additions & 0 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,75 @@ def test_show_top_level_with_explicitly_defined_depenancy(
assert tester.io.fetch_output() == expected


def test_show_top_level_with_extras(
tester: CommandTester, poetry: Poetry, installed: Repository
) -> None:
black_dep = Factory.create_dependency(
"black", {"version": "23.3.0", "extras": ["d"]}
)
poetry.package.add_dependency(black_dep)

black_package = get_package("black", "23.3.0")
black_package.add_dependency(
Factory.create_dependency(
"aiohttp",
{
"version": ">=3.7.4",
"optional": True,
"markers": 'extra == "d"',
},
)
)
installed.add_package(black_package)

assert isinstance(poetry.locker, TestLocker)
poetry.locker.mock_lock_data(
{
"package": [
{
"name": "black",
"version": "23.3.0",
"description": "",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
"dependencies": {
"aiohttp": {
"version": ">=3.7.4",
"optional": True,
"markers": 'extra == "d"',
}
},
},
{
"name": "aiohttp",
"version": "3.8.4",
"description": "",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"files": {"black": [], "aiohttp": []},
},
}
)

tester.execute("--top-level")

expected = """black 23.3.0 \n"""

assert tester.io.fetch_output() == expected


def test_show_error_top_level_with_tree(tester: CommandTester) -> None:
expected = "Error: Cannot use --tree and --top-level at the same time.\n"
tester.execute("--top-level --tree")
Expand Down

0 comments on commit 15d78fa

Please sign in to comment.