Skip to content

Commit

Permalink
Merge pull request #237 from twidi/correctly-load-pylint-plugins-options
Browse files Browse the repository at this point in the history
Load pylint plugins before pylint config
  • Loading branch information
chocoelho committed May 25, 2018
2 parents ea02ba5 + 221df28 commit 7502179
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions prospector/tools/pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def _error_message(self, filepath, message):
def _pylintrc_configure(self, pylintrc, linter):
errors = []
linter.load_default_plugins()
linter.config_from_file(pylintrc)
if hasattr(linter.config, 'load_plugins'):
are_plugins_loaded = linter.config_from_file(pylintrc)
if not are_plugins_loaded and hasattr(linter.config, 'load_plugins'):
for plugin in linter.config.load_plugins:
try:
linter.load_plugin_modules([plugin])
Expand Down
12 changes: 10 additions & 2 deletions prospector/tools/pylint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pylint.__pkginfo__ import numversion as PYLINT_VERSION
if PYLINT_VERSION >= (1, 5):
from pylint.config import OptionsManagerMixIn
from pylint.utils import _splitstrip
else:
from logilab.common.configuration import OptionsManagerMixIn
from pylint.lint import PyLinter
Expand All @@ -17,11 +18,18 @@ def __init__(self, found_files, *args, **kwargs):
PyLinter.__init__(self, *args, **kwargs)

def config_from_file(self, config_file=None):
"""Will return `True` if plugins have been loaded. For pylint>=1.5. Else `False`."""
if PYLINT_VERSION >= (1, 5):
self.read_config_file(config_file)
if self.cfgfile_parser.has_option('MASTER', 'load-plugins'):
# pylint: disable=protected-access
plugins = _splitstrip(self.cfgfile_parser.get('MASTER', 'load-plugins'))
self.load_plugin_modules(plugins)
self.load_config_file()
else:
self.load_file_configuration(config_file)
return True

self.load_file_configuration(config_file)
return False

def reset_options(self):
# for example, we want to re-initialise the OptionsManagerMixin
Expand Down

0 comments on commit 7502179

Please sign in to comment.