Skip to content

Commit d3dfbbd

Browse files
committed
Add support for new load_configuration hook of pylint
1 parent bb0153b commit d3dfbbd

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
* [atodorov](https://github.com/atodorov)
1010
* [bittner](https://github.com/bittner)
1111
* [federicobond](https://github.com/federicobond)
12+
* [matusvalo](https://github.com/matusvalo)

pylint_django/checkers/db_performance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pylint import checkers
1414
from pylint.checkers import utils
1515
from pylint_django.__pkginfo__ import BASE_ID
16+
from pylint_django import compat
1617

1718

1819
def _is_addfield_with_default(call):
@@ -113,12 +114,16 @@ def _path(node):
113114
self.add_message('new-db-field-with-default', args=module.name, node=node)
114115

115116

116-
def register(linter):
117-
"""Required method to auto register this checker."""
117+
def load_configuration(linter):
118118
# don't blacklist migrations for this checker
119119
new_black_list = list(linter.config.black_list)
120120
if 'migrations' in new_black_list:
121121
new_black_list.remove('migrations')
122122
linter.config.black_list = new_black_list
123123

124+
125+
def register(linter):
126+
"""Required method to auto register this checker."""
124127
linter.register_checker(NewDbFieldWithDefaultChecker(linter))
128+
if not compat.LOAD_CONFIGURATION_SUPPORTED:
129+
load_configuration(linter)

pylint_django/compat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
except ImportError:
2323
from astroid.util import Uninferable
2424

25+
import pylint
26+
27+
# pylint before version 2.3 does not support load_configuration() hook.
28+
LOAD_CONFIGURATION_SUPPORTED = pylint.__pkginfo__.numversion >= (2, 3)

pylint_django/plugin.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
# we want to import the transforms to make sure they get added to the astroid manager,
88
# however we don't actually access them directly, so we'll disable the warning
99
from pylint_django import transforms # noqa, pylint: disable=unused-import
10+
from pylint_django import compat
1011

1112

12-
def register(linter):
13+
def load_configuration(linter):
1314
"""
14-
Registering additional checkers.
15-
16-
However, we will also use it to amend existing checker config.
15+
Amend existing checker config.
1716
"""
1817
name_checker = get_checker(linter, NameChecker)
1918
name_checker.config.good_names += ('qs', 'urlpatterns', 'register', 'app_name', 'handler500')
2019

2120
# we don't care about South migrations
2221
linter.config.black_list += ('migrations', 'south_migrations')
2322

23+
24+
def register(linter):
25+
"""
26+
Registering additional checkers.
27+
"""
2428
# add all of the checkers
2529
register_checkers(linter)
2630

@@ -32,3 +36,6 @@ def register(linter):
3236
# probably trying to execute pylint_django when Django isn't installed
3337
# in this case the django-not-installed checker will kick-in
3438
pass
39+
40+
if not compat.LOAD_CONFIGURATION_SUPPORTED:
41+
load_configuration(linter)

0 commit comments

Comments
 (0)