From ceb42168d4da617032c5634627a54743d8a710af Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Tue, 10 Oct 2023 01:27:10 +0200 Subject: [PATCH] Stop using imp module it's deprecated since python 3.4 and removed in python 3.12 Signed-off-by: Evan Blaudy --- .../opentimelineio/plugins/python_plugin.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/py-opentimelineio/opentimelineio/plugins/python_plugin.py b/src/py-opentimelineio/opentimelineio/plugins/python_plugin.py index 7a5d3be27a..c511996c99 100644 --- a/src/py-opentimelineio/opentimelineio/plugins/python_plugin.py +++ b/src/py-opentimelineio/opentimelineio/plugins/python_plugin.py @@ -4,10 +4,10 @@ """Base class for OTIO plugins that are exposed by manifests.""" import os -import imp import inspect import collections import copy +import importlib.util from .. import ( core, @@ -110,18 +110,15 @@ def _imported_module(self, namespace): pyname = os.path.splitext(os.path.basename(self.module_abs_path()))[0] pydir = os.path.dirname(self.module_abs_path()) - (file_obj, pathname, description) = imp.find_module(pyname, [pydir]) + spec = importlib.util.spec_from_file_location( + f"opentimelineio.{namespace}.{self.name}", + os.path.join(pydir, f"{pyname}.py"), + ) - with file_obj: - # this will reload the module if it has already been loaded. - mod = imp.load_module( - f"opentimelineio.{namespace}.{self.name}", - file_obj, - pathname, - description - ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) - return mod + return mod def module(self): """Return the module object for this adapter. """