Skip to content

Commit

Permalink
Merge pull request #318 from SergeyKosarchuk/pylint-config
Browse files Browse the repository at this point in the history
Add support pylint --load-plugins option in profile
  • Loading branch information
carlio committed Feb 10, 2019
2 parents 2eeb216 + 5ec1686 commit 684bde1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/profiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ but you can turn it on using the ``--member-warnings`` flag or in a profile::
member-warnings: true


Pylint Plugins
'''''''''''''''

It is possible to specify list of plugins for Pylint. You can do this by using ``load-plugins``
option in ``pylint`` section::

pylint:
load-plugins:
- plugin
- plugin

Note that this option doesn't affect loading of :ref:`autodetected plugins <libraries-used-and-autodetect>`.


PEP8 Control
............

Expand Down
4 changes: 3 additions & 1 deletion prospector/profiles/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def _simple_merge_dict(priority, base):
def _merge_tool_config(priority, base):
out = dict(base.items())
for key, value in priority.items():
if key in ('run', 'full', 'none'): # pep8 has extra 'full' and 'none' options
# pep8 has extra 'full' and 'none' options
# pylint has extra 'load-plugins' option
if key in ('run', 'full', 'none', 'load-plugins'):
out[key] = value
elif key in ('options',):
out[key] = _simple_merge_dict(value, base.get(key, {}))
Expand Down
15 changes: 14 additions & 1 deletion prospector/tools/pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self._orig_sys_path = []

def _prospector_configure(self, prospector_config, linter):
errors = []
linter.load_default_plugins()

if 'django' in prospector_config.libraries:
Expand All @@ -36,6 +37,16 @@ def _prospector_configure(self, prospector_config, linter):
if 'flask' in prospector_config.libraries:
linter.load_plugin_modules(['pylint_flask'])

profile_path = os.path.join(
prospector_config.workdir, prospector_config.profile.name)
for plugin in prospector_config.profile.pylint.get('load-plugins', []):
try:
linter.load_plugin_modules([plugin])
except ImportError:
errors.append(
self._error_message(
profile_path, "Could not load plugin %s" % plugin))

for msg_id in prospector_config.get_disabled_messages('pylint'):
try:
linter.disable(msg_id)
Expand Down Expand Up @@ -91,6 +102,7 @@ def _prospector_configure(self, prospector_config, linter):
if max_line_length is not None:
if option[0] == 'max-line-length':
checker.set_option('max-line-length', max_line_length)
return errors

def _error_message(self, filepath, message):
location = Location(filepath, None, None, 0, 0)
Expand Down Expand Up @@ -186,7 +198,8 @@ def configure(self, prospector_config, found_files):
if not ext_found:
linter.reset_options()
self._args = linter.load_command_line_configuration(check_paths)
self._prospector_configure(prospector_config, linter)
config_messages = self._prospector_configure(
prospector_config, linter)

# Pylint 1.4 introduced the idea of explicitly specifying which
# C-extensions to load. This is because doing so allows them to
Expand Down
5 changes: 5 additions & 0 deletions tests/profiles/profiles/pylint_load_plugins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

pylint:
load-plugins:
- first_plugin
- second_plugin
4 changes: 4 additions & 0 deletions tests/profiles/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def test_disable_tool(self):
self.assertFalse(profile.is_tool_enabled('pylint'))
self.assertTrue(profile.is_tool_enabled('pep8') is None)

def test_load_plugins(self):
profile = ProspectorProfile.load('pylint_load_plugins', self._profile_path)
self.assertEqual(['first_plugin', 'second_plugin'], profile.pylint['load-plugins'])


class TestProfileInheritance(ProfileTestBase):

Expand Down

0 comments on commit 684bde1

Please sign in to comment.