1
1
Fork 0
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:
Pradyun S. Gedam 2017-04-08 10:58:53 +05:30
parent 5a02a7d85c
commit 39edb2cfb2
2 changed files with 31 additions and 28 deletions

View file

@ -78,7 +78,7 @@ class ConfigurationCommand(Command):
dest='global_file',
action='store_true',
default=False,
help='Use the global configuration file'
help='Use the system-wide configuration file only'
)
self.cmd_opts.add_option(
@ -86,7 +86,7 @@ class ConfigurationCommand(Command):
dest='user_file',
action='store_true',
default=False,
help='Use the local configuration file'
help='Use the user configuration file only'
)
self.cmd_opts.add_option(
@ -94,7 +94,7 @@ class ConfigurationCommand(Command):
dest='venv_file',
action='store_true',
default=False,
help='Use the virtualenv configuration file'
help='Use the virtualenv configuration file only'
)
self.parser.insert_option_group(0, self.cmd_opts)
@ -121,17 +121,17 @@ class ConfigurationCommand(Command):
action = k
if action is None:
logger.warn(
"ERROR: Need exactly one action (--list, --edit, "
logger.error(
"Need exactly one action (--list, --edit, "
"--get, --set, --unset) to perform."
)
return ERROR
# Determine which configuration files are to be loaded
if options.user_file and options.global_file:
logger.warn(
"ERROR: Need at-most one configuration file to use - pass "
"only one of --global, --user."
if sum([options.user_file, options.global_file, options.venv_file]):
logger.error(
"Need at-most one configuration file to use - pass "
"only one of --global, --user, --venv."
)
return ERROR
@ -143,8 +143,8 @@ class ConfigurationCommand(Command):
elif options.venv_file:
kwargs["load_only"] = "venv"
elif action in ["set", "unset", "edit"]:
logger.warn(
"ERROR: Need one configuration file to modify - pass one of "
logger.error(
"Need one configuration file to modify - pass one of "
"--global, --user, --venv."
)
return ERROR
@ -173,8 +173,8 @@ class ConfigurationCommand(Command):
def open_in_editor(self, options):
if options.editor is None:
logger.warn(
"ERROR: --edit requires an editor to be passed, either using "
logger.error(
"--edit requires an editor to be passed, either using "
"--editor or by setting it in a configuration file."
)
return ERROR
@ -184,8 +184,8 @@ class ConfigurationCommand(Command):
try:
subprocess.check_call([options.editor, file])
except subprocess.CalledProcessError as e:
logger.warn(
"ERROR: Subprocess exited with exit code %d", e.returncode
logger.error(
"Subprocess exited with exit code %d", e.returncode
)
return ERROR
else:
@ -195,7 +195,7 @@ class ConfigurationCommand(Command):
try:
value = self.configuration.get_value(options.get_name)
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
logger.info("%s", value)
@ -223,7 +223,10 @@ class ConfigurationCommand(Command):
try:
self.configuration.save()
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
else:
return SUCCESS

View file

@ -1,4 +1,14 @@
"""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
@ -21,7 +31,7 @@ _need_file_err_msg = "Needed a specific file to be modifying."
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):
"""Make a name consistent regardless of source (environment or file)
"""
@ -38,16 +48,6 @@ def _disassemble_key(name):
def _make_key(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):
"""Handles management of configuration.