|
14 | 14 |
|
15 | 15 | from pip._internal.cli import cmdoptions
|
16 | 16 | from pip._internal.commands import commands_dict, create_command
|
| 17 | +from pip._internal.configuration import _normalize_name |
17 | 18 | from pip._internal.req.req_file import SUPPORTED_OPTIONS
|
18 | 19 |
|
19 | 20 |
|
| 21 | +def convert_cli_option_to_envvar(opt_name: str) -> str: |
| 22 | + undashed_opt_name = _normalize_name(opt_name) |
| 23 | + normalized_opt_name = undashed_opt_name.upper().replace("-", "_") |
| 24 | + return f"PIP_{normalized_opt_name}" |
| 25 | + |
| 26 | + |
| 27 | +def convert_cli_opt_names_to_envvars(original_cli_opt_names: List[str]) -> List[str]: |
| 28 | + return [ |
| 29 | + convert_cli_option_to_envvar(opt_name) for opt_name in original_cli_opt_names |
| 30 | + ] |
| 31 | + |
| 32 | + |
20 | 33 | class PipNewsInclude(rst.Directive):
|
21 | 34 | required_arguments = 1
|
22 | 35 |
|
@@ -130,7 +143,18 @@ def _format_option(
|
130 | 143 | opt_help = option.help.replace("%default", str(option.default))
|
131 | 144 | # fix paths with sys.prefix
|
132 | 145 | opt_help = opt_help.replace(sys.prefix, "<sys.prefix>")
|
133 |
| - return [bookmark_line, "", line, "", " " + opt_help, ""] |
| 146 | + env_var_names = convert_cli_opt_names_to_envvars(option._long_opts) |
| 147 | + env_var_names_src = ", ".join(f"``{env_var}``" for env_var in env_var_names) |
| 148 | + return [ |
| 149 | + bookmark_line, |
| 150 | + "", |
| 151 | + line, |
| 152 | + "", |
| 153 | + f" {opt_help}", |
| 154 | + "", |
| 155 | + f" (environment variable: {env_var_names_src})", |
| 156 | + "", |
| 157 | + ] |
134 | 158 |
|
135 | 159 | def _format_options(
|
136 | 160 | self, options: Iterable[optparse.Option], cmd_name: Optional[str] = None
|
|
0 commit comments