Fix simply running testsuite in meson
[platform/upstream/gstreamer.git] / testsuite / overrides_hack.py
1 import os
2 import gi.overrides
3
4 try:
5     import mesonconfig
6 except ImportError:
7     mesonconfig = None
8     pass
9
10 FILE = os.path.realpath(__file__)
11 if not gi.overrides.__path__[0].endswith("gst-python/gi/overrides"):
12     local_overrides = None
13     # our overrides don't take precedence, let's fix it
14     for i, path in enumerate(gi.overrides.__path__):
15         if path.endswith("gst-python/gi/overrides"):
16             local_overrides = path
17
18     if local_overrides:
19         gi.overrides.__path__.remove(local_overrides)
20     else:
21         local_overrides = os.path.abspath(os.path.join(FILE, "../", "../", "gi", "overrides"))
22
23     gi.overrides.__path__.insert(0, local_overrides)
24
25 if mesonconfig:
26     gi.overrides.__path__.insert(0, os.path.abspath(os.path.join(mesonconfig.path, "gi", "overrides")))
27 # Execute previously set sitecustomize.py script if it existed
28 if os.environ.get("GST_ENV"):
29     old_sitecustomize = os.path.join(os.path.dirname(__file__),
30                                     "old.sitecustomize.gstuninstalled.py")
31     if os.path.exists(old_sitecustomize):
32         exec(compile(open(old_sitecustomize).read(), old_sitecustomize, 'exec'))