Skip to content

Commit

Permalink
Merge pull request #12304 from pradyunsg/better-rich-presentation
Browse files Browse the repository at this point in the history
Rework how the logging stack handles rich objects
  • Loading branch information
pradyunsg authored Oct 1, 2023
2 parents 71df02c + 3f6e816 commit f6b445b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def exc_logging_wrapper(*args: Any) -> int:
assert isinstance(status, int)
return status
except DiagnosticPipError as exc:
logger.error("[present-rich] %s", exc)
logger.error("%s", exc, extra={"rich": True})
logger.debug("Exception information:", exc_info=True)

return ERROR
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/self_outdated_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def pip_self_version_check(session: PipSession, options: optparse.Values) -> Non
),
)
if upgrade_prompt is not None:
logger.warning("[present-rich] %s", upgrade_prompt)
logger.warning("%s", upgrade_prompt, extra={"rich": True})
except Exception:
logger.warning("There was an error checking the latest version of pip.")
logger.debug("See below for error", exc_info=True)
4 changes: 2 additions & 2 deletions src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def emit(self, record: logging.LogRecord) -> None:

# If we are given a diagnostic error to present, present it with indentation.
assert isinstance(record.args, tuple)
if record.msg == "[present-rich] %s" and len(record.args) == 1:
rich_renderable = record.args[0]
if getattr(record, "rich", False):
(rich_renderable,) = record.args
assert isinstance(
rich_renderable, (ConsoleRenderable, RichCast, str)
), f"{rich_renderable} is not rich-console-renderable"
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def call_subprocess(
output_lines=all_output if not showing_subprocess else None,
)
if log_failed_cmd:
subprocess_logger.error("[present-rich] %s", error)
subprocess_logger.error("%s", error, extra={"rich": True})
subprocess_logger.verbose(
"[bold magenta]full command[/]: [blue]%s[/]",
escape(format_command_args(cmd)),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def test_info_logging__subprocess_error(
expected = (
None,
[
# pytest's caplog overrides th formatter, which means that we
# pytest's caplog overrides the formatter, which means that we
# won't see the message formatted through our formatters.
("pip.subprocessor", ERROR, "[present-rich]"),
("pip.subprocessor", ERROR, "subprocess error exited with 1"),
],
)
# The spinner should spin three times in this case since the
Expand Down

0 comments on commit f6b445b

Please sign in to comment.