Skip to content

Commit 84f76b2

Browse files
committed
Replace imp with importlib
The imp module has been deprecated in 3.4 and remove in 3.12 Function for load_source is taken from the importlib documentation Importing a source file directly That function renamed from import_from_path
1 parent a859970 commit 84f76b2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

suplemon/module_loader.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
Addon module loader.
44
"""
55
import os
6-
import imp
6+
import importlib.util
7+
import sys
78
import logging
89

10+
def load_source(module_name, file_path):
11+
spec = importlib.util.spec_from_file_location(module_name, file_path)
12+
module = importlib.util.module_from_spec(spec)
13+
sys.modules[module_name] = module
14+
spec.loader.exec_module(module)
15+
return module
916

1017
class ModuleLoader:
1118
def __init__(self, app=None):
@@ -63,7 +70,7 @@ def load_single(self, name):
6370
"""Load single module file."""
6471
path = os.path.join(self.module_path, name+".py")
6572
try:
66-
mod = imp.load_source(name, path)
73+
mod = load_source(name, path)
6774
except:
6875
self.logger.error("Failed loading module: {0}".format(name), exc_info=True)
6976
return False

0 commit comments

Comments
 (0)