Skip to content

Commit

Permalink
Allow specifying verbose/quite level via config file and env var
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Jul 13, 2020
1 parent 8bf5731 commit 3848708
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
4 changes: 4 additions & 0 deletions news/8578.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Allow specifying verbosity and quite level via configuration files
and environmental variables. Previously these options were treated as
boolean values when read from there while through CLI the level can be
specified.
43 changes: 27 additions & 16 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,20 @@ def _update_defaults(self, defaults):
if option is None:
continue

if option.action in ('store_true', 'store_false', 'count'):
if option.action in ('store_true', 'store_false'):
try:
val = strtobool(val)
except ValueError:
error_msg = invalid_config_error_message(
option.action, key, val
)
self.error(error_msg)

self.error(invalid_store_bool_message(key, val))
elif option.action == 'count':
try:
value = int(val)
except ValueError:
self.error(invalid_count_message(key, val))
if value < 0:
self.error(invalid_count_message(key, val))
else:
val = value
elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
Expand Down Expand Up @@ -253,14 +258,20 @@ def error(self, msg):
self.exit(UNKNOWN_ERROR, "{}\n".format(msg))


def invalid_config_error_message(action, key, val):
def invalid_store_bool_message(key, value):
# type: (str, str) -> str
"""Returns a better error message when invalid configuration option
of action store_false or store_true is provided.
"""
return ("{} is not a valid value for {} option, "
"please specify a boolean value like yes/no, "
"true/false or 1/0 instead.").format(value, key)


def invalid_count_message(key, value):
# type: (str, str) -> str
"""Returns a better error message when invalid configuration option
is provided."""
if action in ('store_true', 'store_false'):
return ("{0} is not a valid value for {1} option, "
"please specify a boolean value like yes/no, "
"true/false or 1/0 instead.").format(val, key)

return ("{0} is not a valid value for {1} option, "
"please specify a numerical value like 1/0 "
"instead.").format(val, key)
of action count is provided.
"""
return ("{} is not a valid value for {} option, "
"please specify a natural number instead.").format(value, key)

0 comments on commit 3848708

Please sign in to comment.