File: __init__.py

package info (click to toggle)
gst-python1.0 1.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 856 kB
  • sloc: python: 7,429; ansic: 1,280; makefile: 30
file content (45 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gi
import os
import sys
import imp
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_module(self, fullname, path=None, target=None):
        if fullname.startswith('gi.overrides'):
            fp = None
            try:
                fp, _, _ = imp.find_module(fullname.split(
                    '.')[-1], os.environ.get('_GI_OVERRIDES_PATH', '').split(os.pathsep),)
            except ImportError:
                return None
            finally:
                if fp:
                    fp.close()
            return self
        return None

    def load_module(self, name):
        if name in sys.modules:
            return sys.modules[name]

        fp, pathname, description = imp.find_module(name.split(
            '.')[-1], os.environ.get('_GI_OVERRIDES_PATH', '').split(os.pathsep),)

        try:
            module = imp.load_module(name, fp, pathname, description)
        finally:
            if fp:
                fp.close()
        sys.modules[name] = module
        return module


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