← Back to Pull requests

Render usage through Rich on option errors #14143

Merged
2ykwang merged 4 files (42 lines) on Jul 05, 2026 19:06 UTC
View on GitHub
2ykwang 2ykwang commented on Jul 04, 2026 05:23 UTC
Author

Fixes #14136

print_usage() fell through to plain optparse and printed the Rich markup literally. override it to render through PipConsole, like print_help().

see below:

before

❯ python -m pip install --updrade

[optparse.groups]Usage:[/]
  ../python -m pip install \[options] <requirement specifier> \[package-index-options] ...
  ../python -m pip install \[options] -r <requirements file> \[package-index-options] ...
  ../python -m pip install \[options] [-e] <vcs project url> ...
  ../python -m pip install \[options] [-e] <local project path> ...
  ../python -m pip install \[options] <archive url/path> ...

no such option: --updrade

after

❯ PYTHONPATH=src python -m pip install --updrade

Usage:
  ../python -m pip install [options] <requirement specifier> [package-index-options] ...
  ../python -m pip install [options] -r <requirements file> [package-index-options] ...
  ../python -m pip install [options] [-e] <vcs project url> ...
  ../python -m pip install [options] [-e] <local project path> ...
  ../python -m pip install [options] <archive url/path> ...

no such option: --updrade

Diff: 42 lines (+40 / -2) across 4 files Reviewer: ichard26 Review duration: 2263m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.30) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.30 · 42 lines diff across 4 files
0.30
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 3 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.225
Real PR Conversation Timeline
5 items
2ykwang 2ykwang commented on code on Jul 04, 2026 05:24 UTC
Code Review
src/pip/_internal/cli/parser.py:1
@@ -344,15 +344,23 @@ def error(self, msg: str) -> NoReturn:
         self.print_usage(sys.stderr)
         self.exit(UNKNOWN_ERROR, f"{msg}\n")
 
-    def print_help(self, file: Any = None) -> None:
+    def _create_console(self, file: Any = None) -> PipConsole:
         # This is unfortunate but necessary since arguments may have not been
         # parsed yet at this point, so detect --no-color manually.
         no_color = (
             "--no-color" in sys.argv
             or bool(strtobool(os.environ.get("PIP_NO_COLOR", "no") or "no"))
             or "NO_COLOR" in os.environ
         )
-        console = PipConsole(
+        return PipConsole(
             theme=Theme(PrettyHelpFormatter.styles), no_color=no_color, file=file
         )
+
+    def print_usage(self, file: Any = None) -> None:
+        if self.usage:
+            console = self._create_console(file)
+            console.print(self.get_usage(), highlight=False)

The trailing newline from get_usage() is intentional, so no rstrip() here.

pip install [options] ...
    <-- blank line
no such option: --updrade

KRRT7 KRRT7 commented on Jul 04, 2026 05:30 UTC
Contributor

whilst I don't disagree, I do think this should build on top of https://github.com/pypa/pip/pull/14026

2ykwang 2ykwang commented on Jul 04, 2026 12:13 UTC
Author

thanks @KRRT7 for the suggestion took a look.

here's my concern.

https://github.com/pypa/pip/blob/c760425cce58acab02aec7693561a4ec3519f4ab/src/pip/_internal/utils/logging.py#L194-L208

the two need different args though (file, theme, soft_wrap), so they pull in different directions.
I think keeping them separate is cleaner. what would we gain by merging?

ichard26 ichard26 approved these changes on Jul 05, 2026 18:56 UTC
Approved Reviewer

Works and looks great, thank you!

I renamed the _create_console method to _create_console_for_help just so it's clear that this console isn't the main console used by pip. Its only purpose is for highlighting help output.

I agree this is logically separate from the linked PR.

Reviewers
Assignees
2ykwang 2ykwang
Labels
risk: low confidence: 91.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 29.9% (LOW) · Higher = larger blast radius
29.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 91.8% · Lower = rushed or shallow review
91.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 2.5% · Safe to merge
2.5%
Repository