Skip to content

Commit f6b445b

Browse files
authored
Merge pull request #12304 from pradyunsg/better-rich-presentation
Rework how the logging stack handles rich objects
2 parents 71df02c + 3f6e816 commit f6b445b

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/pip/_internal/cli/base_command.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def exc_logging_wrapper(*args: Any) -> int:
181181
assert isinstance(status, int)
182182
return status
183183
except DiagnosticPipError as exc:
184-
logger.error("[present-rich] %s", exc)
184+
logger.error("%s", exc, extra={"rich": True})
185185
logger.debug("Exception information:", exc_info=True)
186186

187187
return ERROR

src/pip/_internal/self_outdated_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def pip_self_version_check(session: PipSession, options: optparse.Values) -> Non
233233
),
234234
)
235235
if upgrade_prompt is not None:
236-
logger.warning("[present-rich] %s", upgrade_prompt)
236+
logger.warning("%s", upgrade_prompt, extra={"rich": True})
237237
except Exception:
238238
logger.warning("There was an error checking the latest version of pip.")
239239
logger.debug("See below for error", exc_info=True)

src/pip/_internal/utils/logging.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def emit(self, record: logging.LogRecord) -> None:
155155

156156
# If we are given a diagnostic error to present, present it with indentation.
157157
assert isinstance(record.args, tuple)
158-
if record.msg == "[present-rich] %s" and len(record.args) == 1:
159-
rich_renderable = record.args[0]
158+
if getattr(record, "rich", False):
159+
(rich_renderable,) = record.args
160160
assert isinstance(
161161
rich_renderable, (ConsoleRenderable, RichCast, str)
162162
), f"{rich_renderable} is not rich-console-renderable"

src/pip/_internal/utils/subprocess.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def call_subprocess(
209209
output_lines=all_output if not showing_subprocess else None,
210210
)
211211
if log_failed_cmd:
212-
subprocess_logger.error("[present-rich] %s", error)
212+
subprocess_logger.error("%s", error, extra={"rich": True})
213213
subprocess_logger.verbose(
214214
"[bold magenta]full command[/]: [blue]%s[/]",
215215
escape(format_command_args(cmd)),

tests/unit/test_utils_subprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ def test_info_logging__subprocess_error(
260260
expected = (
261261
None,
262262
[
263-
# pytest's caplog overrides th formatter, which means that we
263+
# pytest's caplog overrides the formatter, which means that we
264264
# won't see the message formatted through our formatters.
265-
("pip.subprocessor", ERROR, "[present-rich]"),
265+
("pip.subprocessor", ERROR, "subprocess error exited with 1"),
266266
],
267267
)
268268
# The spinner should spin three times in this case since the

0 commit comments

Comments
 (0)