Skip to content

Commit

Permalink
helper/plugin: ignore spec_from_loader() possibly returning None
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Oct 5, 2023
1 parent 0cb10ae commit 191ddd6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/helperFunctions/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
from types import ModuleType
from importlib.machinery import ModuleSpec


def discover_analysis_plugins() -> list[ModuleType]:
Expand All @@ -37,10 +38,7 @@ def _import_plugins(plugin_type) -> list[ModuleType]:
module_name = str(plugin_file).replace('/', '.')[len(src_dir + '/') : -len('.py')]

loader = SourceFileLoader(module_name, str(plugin_file))
spec = spec_from_loader(loader.name, loader)
if spec is None:
logging.error(f'Could not import plugin {module_name}: could not create spec from loader')
continue
spec: ModuleSpec = spec_from_loader(loader.name, loader) # type: ignore[assignment]
plugin_module = module_from_spec(spec)

sys.modules[spec.name] = plugin_module
Expand Down

0 comments on commit 191ddd6

Please sign in to comment.