Skip to content

Commit

Permalink
feat: ensure the indexability of dynamically imported packages
Browse files Browse the repository at this point in the history
Signed-off-by: storyicon <storyicon@foxmail.com>
  • Loading branch information
storyicon committed Apr 1, 2024
1 parent bef51ae commit e73a7e4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/script_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
import importlib.util

from modules import errors

import sys

def load_module(path):
module_spec = importlib.util.spec_from_file_location(os.path.basename(path), path)
module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)

if os.path.isfile(path):
sp = os.path.splitext(path)
module_name = sp[0]
else:
module_name = os.path.basename(path)
sys.modules[module_name] = module
return module


Expand Down

0 comments on commit e73a7e4

Please sign in to comment.