Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: poetry show --top-level works with extras #8076

Merged
Merged
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
4 changes: 1 addition & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,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