diff --git a/nikola/nikola.py b/nikola/nikola.py index 4accadcc4..dd39e82d9 100644 --- a/nikola/nikola.py +++ b/nikola/nikola.py @@ -55,20 +55,7 @@ from .post import Post # NOQA from .plugin_manager import PluginCandidate, PluginInfo, PluginManager from .plugin_categories import ( - Command, - LateTask, - PageCompiler, - CompilerExtension, - MarkdownExtension, - RestExtension, - MetadataExtractor, - ShortcodePlugin, - Task, - TaskMultiplier, TemplateSystem, - SignalHandler, - ConfigPlugin, - CommentSystem, PostScanner, Taxonomy, ) @@ -1050,7 +1037,6 @@ def init_plugins(self, commands_only=False, load_all=False): ] + [path for path in extra_plugins_dirs if path] self._plugin_places = [pathlib.Path(p) for p in self._plugin_places] - self.plugin_manager = PluginManager(plugin_places=self._plugin_places) compilers = defaultdict(set) diff --git a/nikola/plugin_categories.py b/nikola/plugin_categories.py index 2abef7ed1..980f9106a 100644 --- a/nikola/plugin_categories.py +++ b/nikola/plugin_categories.py @@ -885,6 +885,7 @@ def get_other_language_variants(self, classification: str, lang: str, classifica """ return [] + CATEGORIES = { "Command": Command, "Task": Task, diff --git a/nikola/plugin_manager.py b/nikola/plugin_manager.py index a9a95bf6f..f1ec91f23 100644 --- a/nikola/plugin_manager.py +++ b/nikola/plugin_manager.py @@ -142,6 +142,7 @@ def locate_plugins(self, force=False) -> List[PluginCandidate]: return self.candidates def load_plugins(self, candidates: List[PluginCandidate]) -> None: + """Load selected candidate plugins.""" plugins_root = Path(__file__).parent.parent for candidate in candidates: @@ -178,7 +179,7 @@ def load_plugins(self, candidates: List[PluginCandidate]) -> None: module_object = importlib.util.module_from_spec(spec) sys.modules[full_module_name] = module_object spec.loader.exec_module(module_object) - except Exception as exc: + except Exception: self.logger.exception(f"{plugin_id} threw an exception while loading") continue @@ -195,7 +196,7 @@ def load_plugins(self, candidates: List[PluginCandidate]) -> None: continue try: plugin_object = plugin_classes[0]() - except Exception as exc: + except Exception: self.logger.exception(f"{plugin_id} threw an exception while creating an instance") continue self.logger.debug(f"Loaded {plugin_id}") @@ -217,16 +218,20 @@ def load_plugins(self, candidates: List[PluginCandidate]) -> None: self._plugins_by_category[plugin_info.category].append(plugin_info) def get_plugins_of_category(self, category: str) -> List[PluginInfo]: + """Get loaded plugins of a given category.""" return self._plugins_by_category.get(category, []) - def get_plugin_by_name(self, name: str, category: str | None = None) -> PluginInfo | None: + def get_plugin_by_name(self, name: str, category: Optional[str] = None) -> Optional[PluginInfo]: + """Get a loaded plugin by name and optionally by category. Returns None if no such plugin is loaded.""" for p in self.plugins: if p.name == name and (category is None or p.category == category): return p # Aliases for Yapsy compatibility def getPluginsOfCategory(self, category: str) -> List[PluginInfo]: + """Get loaded plugins of a given category.""" return self._plugins_by_category.get(category, []) - def getPluginByName(self, name: str, category: str | None = None) -> PluginInfo | None: + def getPluginByName(self, name: str, category: Optional[str] = None) -> Optional[PluginInfo]: + """Get a loaded plugin by name and optionally by category. Returns None if no such plugin is loaded.""" return self.get_plugin_by_name(name, category) diff --git a/tests/helper.py b/tests/helper.py index 495c3d3a5..8fbebdb45 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -9,21 +9,9 @@ import pathlib from contextlib import contextmanager - -import nikola.utils import nikola.shortcodes +import nikola.utils from nikola.plugin_manager import PluginManager -from nikola.plugin_categories import ( - Command, - Task, - LateTask, - TemplateSystem, - PageCompiler, - TaskMultiplier, - CompilerExtension, - MarkdownExtension, - RestExtension, -) __all__ = ["cd", "FakeSite"] diff --git a/tests/test_plugin_manager.py b/tests/test_plugin_manager.py index 380e6a22c..a4039c5a2 100644 --- a/tests/test_plugin_manager.py +++ b/tests/test_plugin_manager.py @@ -76,7 +76,7 @@ def test_locate_plugins_finds_core_and_custom_plugins(): assert first_plugin.source_dir == places[1] assert second_plugin.category == "ConfigPlugin" - assert second_plugin.compiler == None + assert second_plugin.compiler is None assert second_plugin.source_dir == places[1] / "second"