debug-viewer: Fix plugin loading machinery

The previous code was failing at least with Python 3.11 and Python 3.12.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6659>
This commit is contained in:
Philippe Normand 2024-04-16 13:11:02 +01:00 committed by GStreamer Marge Bot
parent a2254a4968
commit 83b1feb4f8

View file

@ -41,22 +41,18 @@ def _load_plugins(path):
import glob import glob
files = glob.glob(os.path.join(path, "*.py")) files = glob.glob(os.path.join(path, "*.py"))
for filename in files: for filename in files:
name = os.path.basename(os.path.splitext(filename)[0]) name = os.path.basename(os.path.splitext(filename)[0])
if name == "__init__": if name == "__init__":
continue continue
finder = importlib.machinery.PathFinder() loader = importlib.machinery.SourceFileLoader(name, filename)
spec = finder.find_spec( spec = importlib.util.spec_from_file_location(name, filename, loader=loader)
name,
os.environ.get('_GI_OVERRIDES_PATH', '').split(os.pathsep)
)
if spec is None: if spec is None:
raise ModuleNotFoundError(name) raise ModuleNotFoundError(name)
module = importlib.util.module_from_spec(spec) module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
yield module yield module