From 734f6e9a2cb3f1d9a5a155c24e5abe4b47874632 Mon Sep 17 00:00:00 2001 From: ctg123 Date: Thu, 14 Mar 2024 13:39:38 +0100 Subject: [PATCH 1/8] Display env vars for pip options in docs Co-authored-by: luismedel --- docs/pip_sphinxext.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py index fe3f41e8b79..4d5a2f17238 100644 --- a/docs/pip_sphinxext.py +++ b/docs/pip_sphinxext.py @@ -14,9 +14,22 @@ from pip._internal.cli import cmdoptions from pip._internal.commands import commands_dict, create_command +from pip._internal.configuration import _normalize_name from pip._internal.req.req_file import SUPPORTED_OPTIONS +def convert_cli_option_to_envvar(opt_name: str) -> str: + undashed_opt_name = _normalize_name(opt_name) + normalized_opt_name = undashed_opt_name.upper().replace("-", "_") + return f"PIP_{normalized_opt_name}" + + +def convert_cli_opt_names_to_envvars(original_cli_opt_names: List[str]) -> List[str]: + return [ + convert_cli_option_to_envvar(opt_name) for opt_name in original_cli_opt_names + ] + + class PipNewsInclude(rst.Directive): required_arguments = 1 @@ -130,7 +143,18 @@ def _format_option( opt_help = option.help.replace("%default", str(option.default)) # fix paths with sys.prefix opt_help = opt_help.replace(sys.prefix, "") - return [bookmark_line, "", line, "", " " + opt_help, ""] + env_var_names = convert_cli_opt_names_to_envvars(option._long_opts) + env_var_names_src = ", ".join(f"``{env_var}``" for env_var in env_var_names) + return [ + bookmark_line, + "", + line, + "", + " " + opt_help, + "", + f" (environment variable: {env_var_names_src})", + "", + ] def _format_options( self, options: Iterable[optparse.Option], cmd_name: Optional[str] = None From 218058b490631aaa7519b0e6b3d81f5904fcf7d1 Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 14:15:18 +0100 Subject: [PATCH 2/8] Add news/ file --- news/12576.doc.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 news/12576.doc.rst diff --git a/news/12576.doc.rst b/news/12576.doc.rst new file mode 100644 index 00000000000..e69de29bb2d From c25dbd5188b0ef30ca82252635bd8152211dfefc Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 14:23:06 +0100 Subject: [PATCH 3/8] Add missing text in news/ file :facepalm: --- news/12576.doc.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/news/12576.doc.rst b/news/12576.doc.rst index e69de29bb2d..e60091dce45 100644 --- a/news/12576.doc.rst +++ b/news/12576.doc.rst @@ -0,0 +1 @@ +Display env vars for pip options in docs \ No newline at end of file From bbef552afcca0e441e52aa311bf2e9c5e6fc87bb Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 16:52:07 +0100 Subject: [PATCH 4/8] Fix EOL issue --- news/12576.doc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12576.doc.rst b/news/12576.doc.rst index e60091dce45..5a930bea160 100644 --- a/news/12576.doc.rst +++ b/news/12576.doc.rst @@ -1 +1 @@ -Display env vars for pip options in docs \ No newline at end of file +Display env vars for pip options in docs From cacc13dbd6c415a617061418cdb82a544d022c81 Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 19:00:45 +0100 Subject: [PATCH 5/8] Apply code suggestion --- docs/pip_sphinxext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py index 4d5a2f17238..16a3206da50 100644 --- a/docs/pip_sphinxext.py +++ b/docs/pip_sphinxext.py @@ -150,7 +150,7 @@ def _format_option( "", line, "", - " " + opt_help, + f" {opt_help}", "", f" (environment variable: {env_var_names_src})", "", From f9bbdce7f85ca8f58aaaa46f2fc459d215ca5333 Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 21:29:59 +0100 Subject: [PATCH 6/8] Clarify changelog fragment --- news/12576.doc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12576.doc.rst b/news/12576.doc.rst index 5a930bea160..2a3984c2481 100644 --- a/news/12576.doc.rst +++ b/news/12576.doc.rst @@ -1 +1 @@ -Display env vars for pip options in docs +Document the environment variables that correspond with CLI options From effa01d3e006217151ac2d94dbfca9b8e8af17ac Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Thu, 14 Mar 2024 22:31:52 +0100 Subject: [PATCH 7/8] Update news/12576.doc.rst Co-authored-by: Paul Moore --- news/12576.doc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12576.doc.rst b/news/12576.doc.rst index 2a3984c2481..6f1acc5c0e5 100644 --- a/news/12576.doc.rst +++ b/news/12576.doc.rst @@ -1 +1 @@ -Document the environment variables that correspond with CLI options +Document the environment variables that correspond to CLI options From 347fa24eeacbf29d2bedbb319e733dc6b3afd003 Mon Sep 17 00:00:00 2001 From: Luis Medel Date: Fri, 15 Mar 2024 00:13:14 +0100 Subject: [PATCH 8/8] Add missing trailing period --- news/12576.doc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12576.doc.rst b/news/12576.doc.rst index 6f1acc5c0e5..b82dd3d583f 100644 --- a/news/12576.doc.rst +++ b/news/12576.doc.rst @@ -1 +1 @@ -Document the environment variables that correspond to CLI options +Document the environment variables that correspond with CLI options.