Skip to content

Commit 2d59bf6

Browse files
authored
--no-truncate flag in show command (#9580)
1 parent 8a1ed35 commit 2d59bf6

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

docs/cli.md

+1
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ required by
10611061
* `--outdated (-o)`: Show the latest version but only for packages that are outdated.
10621062
* `--all (-a)`: Show all packages (even those not compatible with current system).
10631063
* `--top-level (-T)`: Only show explicitly defined packages.
1064+
* `--no-truncate`: Do not truncate the output based on the terminal width.
10641065

10651066
{{% note %}}
10661067
When `--only` is specified, `--with` and `--without` options are ignored.

src/poetry/console/commands/show.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import sys
4+
35
from typing import TYPE_CHECKING
46
from typing import ClassVar
57

@@ -64,6 +66,11 @@ class ShowCommand(GroupCommand, EnvCommand):
6466
"Show all packages (even those not compatible with current system).",
6567
),
6668
option("top-level", "T", "Show only top-level dependencies."),
69+
option(
70+
"no-truncate",
71+
None,
72+
"Do not truncate the output based on the terminal width.",
73+
),
6774
]
6875

6976
help = """The show command displays detailed information about a package, or
@@ -229,7 +236,11 @@ def _display_packages_information(
229236
show_latest = self.option("latest")
230237
show_all = self.option("all")
231238
show_top_level = self.option("top-level")
232-
width = shutil.get_terminal_size().columns
239+
width = (
240+
sys.maxsize
241+
if self.option("no-truncate")
242+
else shutil.get_terminal_size().columns
243+
)
233244
name_length = version_length = latest_length = required_by_length = 0
234245
latest_packages = {}
235246
latest_statuses = {}

tests/console/commands/test_show.py

+60
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,66 @@ def test_show_required_by_deps(
19811981
assert actual == expected
19821982

19831983

1984+
@pytest.mark.parametrize("truncate", [False, True])
1985+
def test_show_entire_description_truncate(
1986+
tester: CommandTester, poetry: Poetry, installed: Repository, truncate: str
1987+
) -> None:
1988+
poetry.package.add_dependency(Factory.create_dependency("cachy", "^0.2.0"))
1989+
1990+
cachy2 = get_package("cachy", "0.2.0")
1991+
cachy2.add_dependency(Factory.create_dependency("msgpack-python", ">=0.5 <0.6"))
1992+
1993+
installed.add_package(cachy2)
1994+
1995+
assert isinstance(poetry.locker, TestLocker)
1996+
poetry.locker.mock_lock_data(
1997+
{
1998+
"package": [
1999+
{
2000+
"name": "cachy",
2001+
"version": "0.2.0",
2002+
"description": "This is a veeeeeeeery long description that might be truncated.",
2003+
"category": "main",
2004+
"optional": False,
2005+
"platform": "*",
2006+
"python-versions": "*",
2007+
"checksum": [],
2008+
"dependencies": {"msgpack-python": ">=0.5 <0.6"},
2009+
},
2010+
{
2011+
"name": "msgpack-python",
2012+
"version": "0.5.1",
2013+
"description": "",
2014+
"category": "main",
2015+
"optional": False,
2016+
"platform": "*",
2017+
"python-versions": "*",
2018+
"checksum": [],
2019+
},
2020+
],
2021+
"metadata": {
2022+
"python-versions": "*",
2023+
"platform": "*",
2024+
"content-hash": "123456789",
2025+
"files": {"cachy": [], "msgpack-python": []},
2026+
},
2027+
}
2028+
)
2029+
2030+
tester.execute("" if truncate else "--no-truncate")
2031+
2032+
if truncate:
2033+
expected = """\
2034+
cachy 0.2.0 This is a veeeeeeeery long description that might ...
2035+
msgpack-python (!) 0.5.1"""
2036+
else:
2037+
expected = """\
2038+
cachy 0.2.0 This is a veeeeeeeery long description that might be truncated.
2039+
msgpack-python (!) 0.5.1"""
2040+
2041+
assert tester.io.fetch_output().strip() == expected
2042+
2043+
19842044
def test_show_errors_without_lock_file(tester: CommandTester, poetry: Poetry) -> None:
19852045
assert not poetry.locker.lock.exists()
19862046

0 commit comments

Comments
 (0)