4from optparse
import Values
5from typing
import Any, List, Optional
12 get_configuration_files,
24 Manage local and global configuration.
28 - list: List the active configuration (or from the file specified)
29 - edit: Edit the configuration file in an editor
30 - get: Get the value associated with command.option
31 - set: Set the command.option=value
32 - unset: Unset the value associated with command.option
33 - debug: List the configuration files and values defined under them
35 Configuration keys should be dot separated command and option name,
36 with the special prefix "global" affecting any command. For example,
37 "pip config set global.index-url https://example.org/" would configure
38 the index url for all commands, but "pip config set download.timeout 10"
39 would configure a 10 second timeout only for "pip download" commands.
41 If none of --user, --global and --site are passed, a virtual
42 environment configuration file is used if one is active and the file
43 exists. Otherwise, all modifications happen to the user file by
47 ignore_require_venv =
True
49 %prog [<file-option>] list
50 %prog [<file-option>] [--editor <editor-path>] edit
52 %prog [<file-option>] get command.option
53 %prog [<file-option>] set command.option value
54 %prog [<file-option>] unset command.option
55 %prog [<file-option>] debug
65 "Editor to use to edit the file. Uses VISUAL or EDITOR "
66 "environment variables if not provided."
75 help=
"Use the system-wide configuration file only",
83 help=
"Use the user configuration file only",
91 help=
"Use the current environment configuration file only",
96 def run(self, options: Values, args: List[str]) -> int:
107 if not args
or args[0]
not in handlers:
109 "Need an action (%s) to perform.",
110 ", ".join(sorted(handlers)),
120 options, need_value=(action
in [
"get",
"set",
"unset",
"edit"])
122 except PipError
as e:
134 handlers[action](options, args[1:])
135 except PipError
as e:
158 for site_config_file
in get_configuration_files()[
kinds.SITE]
163 elif len(file_options) == 1:
164 return file_options[0]
167 "Need exactly one file to operate upon "
168 "(--user, --site, --global) to perform."
175 write_output(
"%s=%r", key, value)
177 def get_name(self, options: Values, args: List[str]) ->
None:
181 write_output(
"%s", value)
184 key, value = self.
_get_n_args(args,
"set [name] [value]", n=2)
189 def unset_name(self, options: Values, args: List[str]) ->
None:
196 """List config key-value pairs across different config files"""
202 for variant, files
in sorted(self.
configuration.iter_config_files()):
203 write_output(
"%s:", variant)
207 write_output(
"%s, exists: %r", fname, file_exists)
212 """Get key-value pairs from the file of a variant"""
213 for name, value
in self.
configuration.get_values_in_config(variant).items():
215 write_output(
"%s: %s", name, value)
218 """Get key-values pairs present as environment variables"""
219 write_output(
"%s:",
"env_var")
221 for key, value
in sorted(self.
configuration.get_environ_vars()):
222 env_var = f
"PIP_{key.upper()}"
223 write_output(
"%s=%r", env_var, value)
230 raise PipError(
"Could not determine appropriate file.")
235 f
'Can not open an editor for a file name containing "\n{fname}'
240 except FileNotFoundError
as e:
246 "Editor Subprocess exited with exit code {}".format(
e.returncode)
249 def _get_n_args(self, args: List[str], example: str, n: int) -> Any:
250 """Helper to make sure the command got the right number of arguments"""
253 "Got unexpected number of arguments, expected {}. "
254 '(example: "{} config {}")'
255 ).format(n, get_prog(), example)
270 "Unable to save configuration. Please report this as a bug."
282 raise PipError(
"Could not determine editor to use.")
str _determine_editor(self, Values options)
Any _get_n_args(self, List[str] args, str example, int n)
None print_env_var_values(self)
None print_config_file_values(self, Kind variant)
None get_name(self, Values options, List[str] args)
None set_name_value(self, Values options, List[str] args)
None unset_name(self, Values options, List[str] args)
None open_in_editor(self, Values options, List[str] args)
None _save_configuration(self)
None list_config_values(self, Values options, List[str] args)
Optional[Kind] _determine_file(self, Values options, bool need_value)
int run(self, Values options, List[str] args)
None list_values(self, Values options, List[str] args)