1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01:00

Replace imp with importlib

This commit is contained in:
Daniel Mach 2022-08-22 15:45:25 +02:00
parent 565797d5a7
commit ddec088efc

View File

@ -3,7 +3,7 @@
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or version 3 (at your option). # either version 2, or version 3 (at your option).
import imp import importlib.util
import inspect import inspect
import os import os
import sys import sys
@ -9431,8 +9431,11 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not extfile.endswith('.py'): if not extfile.endswith('.py'):
continue continue
try: try:
modname = os.path.splitext(extfile)[0] modname = "osc.plugins." + os.path.splitext(extfile)[0]
mod = imp.load_source(modname, os.path.join(plugin_dir, extfile)) spec = importlib.util.spec_from_file_location(modname, os.path.join(plugin_dir, extfile))
mod = importlib.util.module_from_spec(spec)
sys.modules[modname] = mod
spec.loader.exec_module(mod)
# restore the old exec semantic # restore the old exec semantic
mod.__dict__.update(globals()) mod.__dict__.update(globals())
for name in dir(mod): for name in dir(mod):