mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Nicer messages/docstrings, better log level
This commit is contained in:
parent
5a02a7d85c
commit
39edb2cfb2
2 changed files with 31 additions and 28 deletions
|
@ -78,7 +78,7 @@ class ConfigurationCommand(Command):
|
||||||
dest='global_file',
|
dest='global_file',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Use the global configuration file'
|
help='Use the system-wide configuration file only'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cmd_opts.add_option(
|
self.cmd_opts.add_option(
|
||||||
|
@ -86,7 +86,7 @@ class ConfigurationCommand(Command):
|
||||||
dest='user_file',
|
dest='user_file',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Use the local configuration file'
|
help='Use the user configuration file only'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cmd_opts.add_option(
|
self.cmd_opts.add_option(
|
||||||
|
@ -94,7 +94,7 @@ class ConfigurationCommand(Command):
|
||||||
dest='venv_file',
|
dest='venv_file',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Use the virtualenv configuration file'
|
help='Use the virtualenv configuration file only'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.parser.insert_option_group(0, self.cmd_opts)
|
self.parser.insert_option_group(0, self.cmd_opts)
|
||||||
|
@ -121,17 +121,17 @@ class ConfigurationCommand(Command):
|
||||||
action = k
|
action = k
|
||||||
|
|
||||||
if action is None:
|
if action is None:
|
||||||
logger.warn(
|
logger.error(
|
||||||
"ERROR: Need exactly one action (--list, --edit, "
|
"Need exactly one action (--list, --edit, "
|
||||||
"--get, --set, --unset) to perform."
|
"--get, --set, --unset) to perform."
|
||||||
)
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
|
|
||||||
# Determine which configuration files are to be loaded
|
# Determine which configuration files are to be loaded
|
||||||
if options.user_file and options.global_file:
|
if sum([options.user_file, options.global_file, options.venv_file]):
|
||||||
logger.warn(
|
logger.error(
|
||||||
"ERROR: Need at-most one configuration file to use - pass "
|
"Need at-most one configuration file to use - pass "
|
||||||
"only one of --global, --user."
|
"only one of --global, --user, --venv."
|
||||||
)
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ class ConfigurationCommand(Command):
|
||||||
elif options.venv_file:
|
elif options.venv_file:
|
||||||
kwargs["load_only"] = "venv"
|
kwargs["load_only"] = "venv"
|
||||||
elif action in ["set", "unset", "edit"]:
|
elif action in ["set", "unset", "edit"]:
|
||||||
logger.warn(
|
logger.error(
|
||||||
"ERROR: Need one configuration file to modify - pass one of "
|
"Need one configuration file to modify - pass one of "
|
||||||
"--global, --user, --venv."
|
"--global, --user, --venv."
|
||||||
)
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
|
@ -173,8 +173,8 @@ class ConfigurationCommand(Command):
|
||||||
|
|
||||||
def open_in_editor(self, options):
|
def open_in_editor(self, options):
|
||||||
if options.editor is None:
|
if options.editor is None:
|
||||||
logger.warn(
|
logger.error(
|
||||||
"ERROR: --edit requires an editor to be passed, either using "
|
"--edit requires an editor to be passed, either using "
|
||||||
"--editor or by setting it in a configuration file."
|
"--editor or by setting it in a configuration file."
|
||||||
)
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
|
@ -184,8 +184,8 @@ class ConfigurationCommand(Command):
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([options.editor, file])
|
subprocess.check_call([options.editor, file])
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
logger.warn(
|
logger.error(
|
||||||
"ERROR: Subprocess exited with exit code %d", e.returncode
|
"Subprocess exited with exit code %d", e.returncode
|
||||||
)
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
else:
|
else:
|
||||||
|
@ -195,7 +195,7 @@ class ConfigurationCommand(Command):
|
||||||
try:
|
try:
|
||||||
value = self.configuration.get_value(options.get_name)
|
value = self.configuration.get_value(options.get_name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.warn("ERROR: No key %r in configuration", options.get_name)
|
logger.error("No key %r in configuration", options.get_name)
|
||||||
return ERROR
|
return ERROR
|
||||||
|
|
||||||
logger.info("%s", value)
|
logger.info("%s", value)
|
||||||
|
@ -223,7 +223,10 @@ class ConfigurationCommand(Command):
|
||||||
try:
|
try:
|
||||||
self.configuration.save()
|
self.configuration.save()
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Houston, we have a problem", exc_info=1)
|
logger.error(
|
||||||
|
"Unable to save configuration. Please report this as a bug.",
|
||||||
|
exc_info=1
|
||||||
|
)
|
||||||
return ERROR
|
return ERROR
|
||||||
else:
|
else:
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
"""Configuration management setup
|
"""Configuration management setup
|
||||||
|
|
||||||
|
Some terminology:
|
||||||
|
- name
|
||||||
|
As written in config files.
|
||||||
|
- value
|
||||||
|
Value associated with a name
|
||||||
|
- key
|
||||||
|
Name combined with it's section (section.name)
|
||||||
|
- variant
|
||||||
|
A single word describing where the configuration key-value pair came from
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -21,7 +31,7 @@ _need_file_err_msg = "Needed a specific file to be modifying."
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# NOTE: Maybe use the optionx attribtue to normalize keynames.
|
# NOTE: Maybe use the optionx attribute to normalize keynames.
|
||||||
def _normalize_name(name):
|
def _normalize_name(name):
|
||||||
"""Make a name consistent regardless of source (environment or file)
|
"""Make a name consistent regardless of source (environment or file)
|
||||||
"""
|
"""
|
||||||
|
@ -38,16 +48,6 @@ def _disassemble_key(name):
|
||||||
def _make_key(variant, name):
|
def _make_key(variant, name):
|
||||||
return ".".join((variant, name))
|
return ".".join((variant, name))
|
||||||
|
|
||||||
# Some terminology:
|
|
||||||
# - name
|
|
||||||
# As written in config files.
|
|
||||||
# - value
|
|
||||||
# Value associated with a name
|
|
||||||
# - key
|
|
||||||
# Name combined with it's section (section.name)
|
|
||||||
# - variant
|
|
||||||
# A single word describing where the configuration key-value pair came from
|
|
||||||
|
|
||||||
|
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
"""Handles management of configuration.
|
"""Handles management of configuration.
|
||||||
|
|
Loading…
Reference in a new issue