mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-04 23:46:43 +00:00
865b9b59a5
The `imp` module got removed in python 3.12 and the `importlib` module should be used instead. This is also a good excuse to switch to the new finder module from PEP 451 : https://www.python.org/dev/peps/pep-0451/ This only requires implement the `find_spec()` method in our custom loaders Co-authored-by: Stefan <107316-stefan6419846@users.noreply.gitlab.freedesktop.org> Co-authored-by: Jordan Petrids <jordan@centricular.com> Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6050>
27 lines
924 B
Python
27 lines
924 B
Python
import os
|
|
import sys
|
|
import importlib
|
|
|
|
class GstOverrideImport:
|
|
def find_spec(self, fullname, path, target=None):
|
|
if not (fullname.startswith("gi.overrides.Gst") or fullname.startswith("gi.overrides._gi_gst")):
|
|
return None
|
|
finder = importlib.machinery.PathFinder()
|
|
# From find_spec the docs:
|
|
# If name is for a submodule (contains a dot), the parent module is automatically imported.
|
|
spec = finder.find_spec(
|
|
fullname,
|
|
[
|
|
os.environ.get('GST_OVERRIDE_SRC_PATH'),
|
|
os.environ.get('GST_OVERRIDE_BUILD_PATH'),
|
|
]
|
|
)
|
|
return spec
|
|
|
|
if sys.version_info.major >= 3:
|
|
sys.meta_path.insert(0, GstOverrideImport())
|
|
else:
|
|
import gi.overrides
|
|
|
|
gi.overrides.__path__.append(os.environ.get('GST_OVERRIDE_SRC_PATH'))
|
|
gi.overrides.__path__.append(os.environ.get('GST_OVERRIDE_BUILD_PATH'))
|