2021-10-14 20:01:01 +00:00
|
|
|
import gi
|
|
|
|
import os
|
|
|
|
import sys
|
2024-01-04 13:43:20 +00:00
|
|
|
import importlib.util
|
|
|
|
from importlib.machinery import PathFinder
|
2021-10-14 20:01:01 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
# Remove this dummy module the python path and
|
|
|
|
# try to import the actual gi module
|
|
|
|
sys.path.remove(str(Path(__file__).parents[1]))
|
|
|
|
del sys.modules["gi"]
|
|
|
|
import gi
|
|
|
|
|
|
|
|
|
|
|
|
class GstOverrideImport:
|
2024-01-04 13:43:20 +00:00
|
|
|
def find_spec(self, fullname, path, target=None):
|
|
|
|
if not fullname.startswith("gi.overrides"):
|
|
|
|
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('_GI_OVERRIDES_PATH', '').split(os.pathsep)
|
|
|
|
)
|
|
|
|
return spec
|
2021-10-14 20:01:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
sys.meta_path.insert(0, GstOverrideImport())
|