File: __init__.py

package info (click to toggle)
gst-python1.0 1.27.2-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 980 kB
  • sloc: python: 8,200; ansic: 2,023; makefile: 33
file content (29 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gi
import os
import sys
import importlib.util
from importlib.machinery import PathFinder
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:
    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


sys.meta_path.insert(0, GstOverrideImport())