diff --git a/docs/cli.md b/docs/cli.md index d191c54b058..be1bf5166aa 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -1061,6 +1061,7 @@ required by * `--outdated (-o)`: Show the latest version but only for packages that are outdated. * `--all (-a)`: Show all packages (even those not compatible with current system). * `--top-level (-T)`: Only show explicitly defined packages. +* `--no-truncate`: Do not truncate the output based on the terminal width. {{% note %}} When `--only` is specified, `--with` and `--without` options are ignored. diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py index b9e0490ddaa..e606f388a2c 100644 --- a/src/poetry/console/commands/show.py +++ b/src/poetry/console/commands/show.py @@ -1,5 +1,7 @@ from __future__ import annotations +import sys + from typing import TYPE_CHECKING from typing import ClassVar @@ -64,6 +66,11 @@ class ShowCommand(GroupCommand, EnvCommand): "Show all packages (even those not compatible with current system).", ), option("top-level", "T", "Show only top-level dependencies."), + option( + "no-truncate", + None, + "Do not truncate the output based on the terminal width.", + ), ] help = """The show command displays detailed information about a package, or @@ -229,7 +236,11 @@ def _display_packages_information( show_latest = self.option("latest") show_all = self.option("all") show_top_level = self.option("top-level") - width = shutil.get_terminal_size().columns + width = ( + sys.maxsize + if self.option("no-truncate") + else shutil.get_terminal_size().columns + ) name_length = version_length = latest_length = required_by_length = 0 latest_packages = {} latest_statuses = {} diff --git a/tests/console/commands/test_show.py b/tests/console/commands/test_show.py index 22594af6e87..30ebb92f069 100644 --- a/tests/console/commands/test_show.py +++ b/tests/console/commands/test_show.py @@ -1981,6 +1981,66 @@ def test_show_required_by_deps( assert actual == expected +@pytest.mark.parametrize("truncate", [False, True]) +def test_show_entire_description_truncate( + tester: CommandTester, poetry: Poetry, installed: Repository, truncate: str +) -> None: + poetry.package.add_dependency(Factory.create_dependency("cachy", "^0.2.0")) + + cachy2 = get_package("cachy", "0.2.0") + cachy2.add_dependency(Factory.create_dependency("msgpack-python", ">=0.5 <0.6")) + + installed.add_package(cachy2) + + assert isinstance(poetry.locker, TestLocker) + poetry.locker.mock_lock_data( + { + "package": [ + { + "name": "cachy", + "version": "0.2.0", + "description": "This is a veeeeeeeery long description that might be truncated.", + "category": "main", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + "dependencies": {"msgpack-python": ">=0.5 <0.6"}, + }, + { + "name": "msgpack-python", + "version": "0.5.1", + "description": "", + "category": "main", + "optional": False, + "platform": "*", + "python-versions": "*", + "checksum": [], + }, + ], + "metadata": { + "python-versions": "*", + "platform": "*", + "content-hash": "123456789", + "files": {"cachy": [], "msgpack-python": []}, + }, + } + ) + + tester.execute("" if truncate else "--no-truncate") + + if truncate: + expected = """\ +cachy 0.2.0 This is a veeeeeeeery long description that might ... +msgpack-python (!) 0.5.1""" + else: + expected = """\ +cachy 0.2.0 This is a veeeeeeeery long description that might be truncated. +msgpack-python (!) 0.5.1""" + + assert tester.io.fetch_output().strip() == expected + + def test_show_errors_without_lock_file(tester: CommandTester, poetry: Poetry) -> None: assert not poetry.locker.lock.exists()