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

--no-truncate flag in show command #9580

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
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import sys

from typing import TYPE_CHECKING
from typing import ClassVar

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down
60 changes: 60 additions & 0 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down