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.
"""
try:
import imp
fp, pathname, description = imp.find_module(pdata.mod_name, [pdata.fpath])
try:
module = imp.load_module(pdata.mod_name, fp, pathname,description)
finally:
if fp:
fp.close()
spec = importlib.util.find_spec(pdata.mod_name, [pdata.fpath])
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except:
if pdata.mod_name in sys.modules:
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.
module = __import__("gramps.plugins.lib.libgedcom",
fromlist=["gramps.plugins.lib"]) # why o why ?? as above!
import imp
imp.reload(module)
import importlib
importlib.reload(module)
from gramps.gen.config import config