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
files = glob.glob(os.path.join(path, "*.py"))
for filename in files:
name = os.path.basename(os.path.splitext(filename)[0])
if name == "__init__":
continue
finder = importlib.machinery.PathFinder()
spec = finder.find_spec(
name,
os.environ.get('_GI_OVERRIDES_PATH', '').split(os.pathsep)
)
loader = importlib.machinery.SourceFileLoader(name, filename)
spec = importlib.util.spec_from_file_location(name, filename, loader=loader)
if spec is None:
raise ModuleNotFoundError(name)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
yield module