Skip to content

Commit

Permalink
Keep original indention of Python traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Feb 23, 2024
1 parent b6778bb commit 70ce1b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This version is not released yet and is under active development.

- \[pkg\] Add support for `pkg` on FreeBSD.
- \[choco\] Bump minimal `choco` requirement to `2.0.0`.
- \[bar-plugin\] Keep original indention of Python traceback.
- \[mpm\] Build `arm64` binaries on `macos-14`.
- \[mpm\] Run tests on `macos-14` instead of `macos-13`.
- \[mpm\] Run tests on Python 3.13-dev branch.
Expand Down
21 changes: 13 additions & 8 deletions meta_package_manager/bar_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,18 @@ def pp(label: str, *args: str) -> None:
First argument is the menu-line label, separated by a pipe to all other non-
empty parameters, themselves separated by a space.
Skip printing of the line if label is empty.
"""
print(
label.strip(),
"|",
*(line for line in map(methodcaller("strip"), args) if line),
sep=" ",
)
if label.strip():
print(
# Do not strip the label to keep character alignements, especially in
# table rendering and Python tracebacks.
label,
"|",
*(line for line in map(methodcaller("strip"), args) if line),
sep=" ",
)

@staticmethod
def print_error_header() -> None:
Expand All @@ -297,12 +302,12 @@ def print_error(self, message: str | Exception, submenu: str = "") -> None:
"""Print a formatted error message line by line.
A red, fixed-width font is used to preserve traceback and exception layout. For
compactness, the message is dedented and empty lines are skipped.
compactness, the block message is dedented and empty lines are skipped.
Message is always casted to a string as we allow passing of exception objects
and have them rendered.
"""
for line in map(methodcaller("strip"), dedent(str(message)).splitlines()):
for line in map(methodcaller("rstrip"), dedent(str(message)).splitlines()):
if line:
self.pp(
f"{submenu}{line}",
Expand Down

0 comments on commit 70ce1b6

Please sign in to comment.