replace deprecated use of SourceFileLoader.load_module

This commit is contained in:
Maximilian Hils 2017-07-20 15:23:22 +02:00
parent 779677bcc6
commit 94d28831e1

View File

@ -24,12 +24,14 @@ def load_script(actx, path):
# the fullname is not unique among scripts, so if there already is an existing script with said
# fullname, remove it.
sys.modules.pop(fullname, None)
loader = importlib.machinery.SourceFileLoader(fullname, path)
try:
oldpath = sys.path
sys.path.insert(0, os.path.dirname(path))
with addonmanager.safecall():
m = loader.load_module()
loader = importlib.machinery.SourceFileLoader(fullname, path)
spec = importlib.util.spec_from_loader(fullname, loader=loader)
m = importlib.util.module_from_spec(spec)
loader.exec_module(m)
if not getattr(m, "name", None):
m.name = path
return m