File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ from importlib import import_module
2
+
3
+ from pylint .checkers import BaseChecker
4
+ from pylint .lint .pylinter import PyLinter
5
+
6
+
7
+ class ImportingChecker (BaseChecker ):
8
+ options = (
9
+ (
10
+ "settings-module" ,
11
+ {
12
+ "default" : "settings" ,
13
+ "type" : "string" ,
14
+ "metavar" : "<settings module>"
15
+ },
16
+ ),
17
+ )
18
+
19
+ msgs = {
20
+ "E9999" : (
21
+ "Importing checker error message" ,
22
+ "importing-checker-error" ,
23
+ "Importing checker error message" ,
24
+ ),
25
+ }
26
+
27
+ def open (self ) -> None :
28
+ import_module (self .linter .config .settings_module )
29
+
30
+
31
+ def register (linter : "PyLinter" ) -> None :
32
+ linter .register_checker (ImportingChecker (linter ))
Original file line number Diff line number Diff line change @@ -869,6 +869,19 @@ def test_modify_sys_path() -> None:
869
869
modify_sys_path ()
870
870
assert sys .path == paths [1 :]
871
871
872
+ @staticmethod
873
+ def test_plugin_that_imports_from_open () -> None :
874
+ """Test that a plugin that imports a source file from a checker open()
875
+ function (ala pylint_django) does not raise an exception."""
876
+ with _test_sys_path ():
877
+ # Enable --load-plugins=importing_plugin
878
+ sys .path .append (join (HERE , "regrtest_data" , "importing_plugin" ))
879
+ with _test_cwd (join (HERE , "regrtest_data" , "settings_project" )):
880
+ Run (
881
+ ["--load-plugins=importing_plugin" , "models.py" ],
882
+ exit = False ,
883
+ )
884
+
872
885
@pytest .mark .parametrize (
873
886
"args" ,
874
887
[
You can’t perform that action at this time.
0 commit comments