Replace deprecated imp by importlib

This commit is contained in:
David Straub 2023-02-06 17:12:28 +01:00 committed by Nick Hall
parent 30663f2113
commit 47f392ef70
2 changed files with 5 additions and 9 deletions

View File

@ -372,13 +372,9 @@ class BasePluginManager:
Reloads modules that might not be in the path. Reloads modules that might not be in the path.
""" """
try: try:
import imp spec = importlib.util.find_spec(pdata.mod_name, [pdata.fpath])
fp, pathname, description = imp.find_module(pdata.mod_name, [pdata.fpath]) module = importlib.util.module_from_spec(spec)
try: spec.loader.exec_module(module)
module = imp.load_module(pdata.mod_name, fp, pathname,description)
finally:
if fp:
fp.close()
except: except:
if pdata.mod_name in sys.modules: if pdata.mod_name in sys.modules:
del sys.modules[pdata.mod_name] del sys.modules[pdata.mod_name]

View File

@ -47,8 +47,8 @@ from gramps.gen.utils.libformatting import ImportInfo
# a quick turnround, without having to restart Gramps. # a quick turnround, without having to restart Gramps.
module = __import__("gramps.plugins.lib.libgedcom", module = __import__("gramps.plugins.lib.libgedcom",
fromlist=["gramps.plugins.lib"]) # why o why ?? as above! fromlist=["gramps.plugins.lib"]) # why o why ?? as above!
import imp import importlib
imp.reload(module) importlib.reload(module)
from gramps.gen.config import config from gramps.gen.config import config