From e59ff2fc8ca1d58fceb7a82cb67694a98bfa4982 Mon Sep 17 00:00:00 2001 From: doron zarhi Date: Tue, 6 Dec 2022 14:20:18 +0200 Subject: [PATCH] show: add editable location if package is editable (#11638) --- news/11638.bugfix.rst | 1 + src/pip/_internal/commands/show.py | 6 ++++++ tests/functional/test_show.py | 9 +++++---- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 news/11638.bugfix.rst diff --git a/news/11638.bugfix.rst b/news/11638.bugfix.rst new file mode 100644 index 00000000000..04ef930bc1b --- /dev/null +++ b/news/11638.bugfix.rst @@ -0,0 +1 @@ +Make ``pip show`` show the editable location if package is editable diff --git a/src/pip/_internal/commands/show.py b/src/pip/_internal/commands/show.py index 212167c9d1e..3f10701f6b2 100644 --- a/src/pip/_internal/commands/show.py +++ b/src/pip/_internal/commands/show.py @@ -53,6 +53,7 @@ class _PackageInfo(NamedTuple): name: str version: str location: str + editable_project_location: Optional[str] requires: List[str] required_by: List[str] installer: str @@ -120,6 +121,7 @@ def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]: name=dist.raw_name, version=str(dist.version), location=dist.location or "", + editable_project_location=dist.editable_project_location, requires=requires, required_by=required_by, installer=dist.installer, @@ -158,6 +160,10 @@ def print_results( write_output("Author-email: %s", dist.author_email) write_output("License: %s", dist.license) write_output("Location: %s", dist.location) + if dist.editable_project_location is not None: + write_output( + "Editable project location: %s", dist.editable_project_location + ) write_output("Requires: %s", ", ".join(dist.requires)) write_output("Required-by: %s", ", ".join(dist.required_by)) diff --git a/tests/functional/test_show.py b/tests/functional/test_show.py index 2fc8ca24270..a7e9022a5c4 100644 --- a/tests/functional/test_show.py +++ b/tests/functional/test_show.py @@ -17,7 +17,7 @@ def test_basic_show(script: PipTestEnvironment) -> None: """ result = script.pip("show", "pip") lines = result.stdout.splitlines() - assert len(lines) == 10 + assert len(lines) == 11 assert "Name: pip" in lines assert f"Version: {__version__}" in lines assert any(line.startswith("Location: ") for line in lines) @@ -33,7 +33,7 @@ def test_show_with_files_not_found(script: PipTestEnvironment, data: TestData) - script.pip("install", "-e", editable) result = script.pip("show", "-f", "SetupPyUTF8") lines = result.stdout.splitlines() - assert len(lines) == 12 + assert len(lines) == 13 assert "Name: SetupPyUTF8" in lines assert "Version: 0.0.0" in lines assert any(line.startswith("Location: ") for line in lines) @@ -128,7 +128,7 @@ def test_report_mixed_not_found(script: PipTestEnvironment) -> None: result = script.pip("show", "Abcd3", "A-B-C", "pip", allow_stderr_warning=True) assert "WARNING: Package(s) not found: A-B-C, Abcd3" in result.stderr lines = result.stdout.splitlines() - assert len(lines) == 10 + assert len(lines) == 11 assert "Name: pip" in lines @@ -213,6 +213,7 @@ def test_all_fields(script: PipTestEnvironment) -> None: "Author-email", "License", "Location", + "Editable project location", "Requires", "Required-by", } @@ -226,7 +227,7 @@ def test_pip_show_is_short(script: PipTestEnvironment) -> None: """ result = script.pip("show", "pip") lines = result.stdout.splitlines() - assert len(lines) <= 10 + assert len(lines) <= 11 def test_pip_show_divider(script: PipTestEnvironment, data: TestData) -> None: