From 15d78fa246e56fc8295062f014dd4304ad96cb15 Mon Sep 17 00:00:00 2001 From: ralbertazzi Date: Wed, 7 Jun 2023 13:59:08 +0200 Subject: [PATCH] fix: poetry show --top-level works with extras --- src/poetry/console/commands/show.py | 4 +- tests/console/commands/test_show.py | 69 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py index 090e5ca17a7..09352b95522 100644 --- a/src/poetry/console/commands/show.py +++ b/src/poetry/console/commands/show.py @@ -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: diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py index bd7dd37e9b4..162fa73a13d 100644 --- a/tests/console/commands/test_show.py +++ b/tests/console/commands/test_show.py @@ -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")