summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-05-14 09:06:16 -0400
committerGitHub <noreply@github.com>2023-05-14 09:06:16 -0400
commit4e48d46b7239c2d7a70a05929fd49595d45cc29f (patch)
treeacec40ebd24109f8ef06ed8b93c0f940fa24ea9a /pylint
parentaed3c080388a8dc1d44c1a14a5ed243233f77c1c (diff)
downloadpylint-git-4e48d46b7239c2d7a70a05929fd49595d45cc29f.tar.gz
Load custom plugins when linting in parallel (#8683)
Diffstat (limited to 'pylint')
-rw-r--r--pylint/lint/parallel.py5
-rw-r--r--pylint/lint/pylinter.py9
2 files changed, 11 insertions, 3 deletions
diff --git a/pylint/lint/parallel.py b/pylint/lint/parallel.py
index e57c7e8ab..72f770043 100644
--- a/pylint/lint/parallel.py
+++ b/pylint/lint/parallel.py
@@ -52,6 +52,11 @@ def _worker_initialize(
_worker_linter.set_reporter(reporters.CollectingReporter())
_worker_linter.open()
+ # Re-register dynamic plugins, since the pool does not have access to the
+ # astroid module that existed when the linter was pickled.
+ _worker_linter.load_plugin_modules(_worker_linter._dynamic_plugins, force=True)
+ _worker_linter.load_plugin_configuration()
+
if extra_packages_paths:
_augment_sys_path(extra_packages_paths)
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index ed607aca5..324c54b1b 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -13,7 +13,7 @@ import sys
import tokenize
import traceback
from collections import defaultdict
-from collections.abc import Callable, Iterator, Sequence
+from collections.abc import Callable, Iterable, Iterator, Sequence
from io import TextIOWrapper
from pathlib import Path
from re import Pattern
@@ -363,15 +363,18 @@ class PyLinter(
checkers.initialize(self)
reporters.initialize(self)
- def load_plugin_modules(self, modnames: list[str]) -> None:
+ def load_plugin_modules(self, modnames: Iterable[str], force: bool = False) -> None:
"""Check a list of pylint plugins modules, load and register them.
If a module cannot be loaded, never try to load it again and instead
store the error message for later use in ``load_plugin_configuration``
below.
+
+ If `force` is True (useful when multiprocessing), then the plugin is
+ reloaded regardless if an entry exists in self._dynamic_plugins.
"""
for modname in modnames:
- if modname in self._dynamic_plugins:
+ if modname in self._dynamic_plugins and not force:
continue
try:
module = astroid.modutils.load_module_from_name(modname)