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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -529,6 +529,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
27 changes: 19 additions & 8 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 @@ -306,14 +311,18 @@ def _display_packages_information(
required_by_length, len(" from " + ",".join(required_by.keys()))
)

write_version = name_length + version_length + 3 <= width
write_latest = name_length + version_length + latest_length + 3 <= width
if self.option("no-truncate"):
write_version = write_latest = write_description = True
write_why = self.option("why")
else:
write_version = name_length + version_length + 3 <= width
write_latest = name_length + version_length + latest_length + 3 <= width

why_end_column = (
name_length + version_length + latest_length + required_by_length
)
write_why = self.option("why") and (why_end_column + 3) <= width
write_description = (why_end_column + 24) <= width
why_end_column = (
name_length + version_length + latest_length + required_by_length
)
write_why = self.option("why") and (why_end_column + 3) <= width
write_description = (why_end_column + 24) <= width

requires = root.all_requires

Expand Down Expand Up @@ -391,7 +400,9 @@ def _display_packages_information(
if show_latest:
remaining -= latest_length

if len(locked.description) > remaining:
if len(locked.description) > remaining and not self.option(
"no-truncate"
):
description = description[: remaining - 3] + "..."

line += " " + description
Expand Down
114 changes: 114 additions & 0 deletions tests/console/commands/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,120 @@ def test_show_required_by_deps(
assert actual == expected


def test_show_entire_description_with_no_truncate(
tester: CommandTester, poetry: Poetry, installed: Repository
) -> None:
poetry.package.add_dependency(Factory.create_dependency("cachy", "^0.2.0"))

cachy2 = get_package("cachy", "0.2.0")
cachy2.description = (
"This is a veeeeeeeery long description that should not be truncated."
)
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 should not 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("--no-truncate")

expected = """\
cachy 0.2.0 This is a veeeeeeeery long description that should not be truncated.
msgpack-python (!) 0.5.1"""

assert tester.io.fetch_output().strip() == expected


def test_show_entire_description_with_truncate(
tester: CommandTester, poetry: Poetry, installed: Repository
) -> None:
poetry.package.add_dependency(Factory.create_dependency("cachy", "^0.2.0"))

cachy2 = get_package("cachy", "0.2.0")
cachy2.description = (
"This is a veeeeeeeery long description that should be truncated."
)
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 should 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()

expected = """\
cachy 0.2.0 This is a veeeeeeeery long description that should...
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
Loading