Skip to content

Commit

Permalink
Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Jan 2, 2024
1 parent 4315f57 commit aef6c8b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
14 changes: 0 additions & 14 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions nikola/plugin_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ def get_other_language_variants(self, classification: str, lang: str, classifica
"""
return []


CATEGORIES = {
"Command": Command,
"Task": Task,
Expand Down
13 changes: 9 additions & 4 deletions nikola/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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}")
Expand All @@ -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)
14 changes: 1 addition & 13 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down

0 comments on commit aef6c8b

Please sign in to comment.