Skip to content

Commit

Permalink
Expose quiet mode to command line
Browse files Browse the repository at this point in the history
The quiet option is parsed in Run.preprocess_options. This was necessary due to the call order in the Run class constructor. The quiet flag was also moved from OptionsManagerMixIn.init() to OptionsManagerMixin.read_config_file() because it wasn't used anywhere else in the class. Currently, quiet mode only manipulates the display of the config file path ("Using config file ").

Closes #1863
  • Loading branch information
garytyler authored and PCManticore committed May 17, 2018
1 parent 1fd4b1b commit 49eae8a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -40,7 +40,12 @@ Release date: |TBA|
* `too-few-public-methods` is not emitted for dataclasses.

Close #1793

* New quiet mode option, enabled with `--quiet` command line flag, to
suppress display of extra non-checker-related output.

Close #1863

* `undefined-loop-variable` takes in consideration non-empty iterred objects before emitting

Close #2039
Expand Down
1 change: 1 addition & 0 deletions doc/whatsnew/2.0.rst
Expand Up @@ -137,6 +137,7 @@ New checkers
def foo(self, bar):
self = bar
* New quiet mode option `--quiet` to suppress display of extra non-checker-related output.

Other Changes
=============
Expand Down
7 changes: 3 additions & 4 deletions pylint/config.py
Expand Up @@ -460,7 +460,7 @@ def format_tail(pkginfo):
class OptionsManagerMixIn(object):
"""Handle configuration from both a configuration file and command line options"""

def __init__(self, usage, config_file=None, version=None, quiet=0):
def __init__(self, usage, config_file=None, version=None):
self.config_file = config_file
self.reset_parsers(usage, version=version)
# list of registered options providers
Expand All @@ -471,7 +471,6 @@ def __init__(self, usage, config_file=None, version=None, quiet=0):
self._nocallback_options = {}
self._mygroups = {}
# verbosity
self.quiet = quiet
self._maxlevel = 0

def reset_parsers(self, usage='', version=None):
Expand Down Expand Up @@ -617,7 +616,7 @@ def load_provider_defaults(self):
for provider in self.options_providers:
provider.load_defaults()

def read_config_file(self, config_file=None):
def read_config_file(self, config_file=None, quiet=None):
"""read the configuration file but do not load it (i.e. dispatching
values to each options provider)
"""
Expand Down Expand Up @@ -657,7 +656,7 @@ def helpfunc(option, opt, val, p, level=helplevel):
if not sect.isupper() and values:
parser._sections[sect.upper()] = values

if self.quiet:
if quiet:
return

if use_config_file:
Expand Down
11 changes: 10 additions & 1 deletion pylint/lint.py
Expand Up @@ -1198,12 +1198,14 @@ class Run(object):
def __init__(self, args, reporter=None, do_exit=True):
self._rcfile = None
self._plugins = []
self.quiet = None
try:
preprocess_options(args, {
# option: (callback, takearg)
'init-hook': (cb_init_hook, True),
'rcfile': (self.cb_set_rcfile, True),
'load-plugins': (self.cb_add_plugins, True),
'quiet': (self.cb_quiet_mode, False)
})
except ArgumentPreprocessingError as ex:
print(ex, file=sys.stderr)
Expand Down Expand Up @@ -1273,6 +1275,11 @@ def __init__(self, args, reporter=None, do_exit=True):
'disabled and only messages emitted by the porting '
'checker will be displayed'}),

('quiet',
{'action' : 'callback', 'callback' : self.cb_quiet_mode,
'help' : 'In quiet mode, extra non-checker-related info '
'will not be displayed' })

), option_groups=self.option_groups, pylintrc=self._rcfile)
# register standard checkers
linter.load_default_plugins()
Expand Down Expand Up @@ -1310,7 +1317,7 @@ def __init__(self, args, reporter=None, do_exit=True):
# read configuration
linter.disable('I')
linter.enable('c-extension-no-member')
linter.read_config_file()
linter.read_config_file(quiet=self.quiet)
config_parser = linter.cfgfile_parser
# run init hook, if present, before loading plugins
if config_parser.has_option('MASTER', 'init-hook'):
Expand Down Expand Up @@ -1409,6 +1416,8 @@ def cb_python3_porting_mode(self, *args, **kwargs):
"""Activate only the python3 porting checker."""
self.linter.python3_porting_mode()

def cb_quiet_mode(self, name, value):
self.quiet = True

def cb_list_confidence_levels(option, optname, value, parser):
for level in interfaces.CONFIDENCE_LEVELS:
Expand Down

0 comments on commit 49eae8a

Please sign in to comment.