Skip to content

Commit

Permalink
TYP: fix typing error in plugins (#1973)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
fangchenli and pre-commit-ci[bot] authored Sep 4, 2023
1 parent 23132ae commit 9e05fdf
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/nebari/plugins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import importlib
import itertools
import os
import re
import sys
import typing
from importlib import import_module
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path

import pluggy
Expand Down Expand Up @@ -56,17 +57,21 @@ def __init__(self) -> None:
def load_plugins(self, plugins: typing.List[str]):
def _import_module_from_filename(plugin: str):
module_name = f"_nebari.stages._files.{plugin.replace(os.sep, '.')}"
spec = importlib.util.spec_from_file_location(module_name, plugin)
mod = importlib.util.module_from_spec(spec)
sys.modules[module_name] = mod
spec.loader.exec_module(mod)
return mod
spec = spec_from_file_location(module_name, plugin)
if spec is None:
raise ImportError(f"Can not find {plugin!r} plugin.")
if spec.loader is None:
raise ImportError(f"Can not load {plugin!r} plugin.")
module = module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module

for plugin in plugins:
if plugin.endswith(".py"):
mod = _import_module_from_filename(plugin)
else:
mod = importlib.import_module(plugin)
mod = import_module(plugin)

try:
self.plugin_manager.register(mod, plugin)
Expand Down

0 comments on commit 9e05fdf

Please sign in to comment.