gir: use GLib to get gir base paths

This commit is contained in:
Peter Eisenmann 2024-03-29 02:14:00 +01:00
parent ca4ef1db88
commit 9429ac5f41

View file

@ -25,7 +25,8 @@ from functools import cached_property
import gi # type: ignore import gi # type: ignore
gi.require_version("GIRepository", "2.0") gi.require_version("GIRepository", "2.0")
from gi.repository import GIRepository # type: ignore gi.require_version("GLib", "2.0")
from gi.repository import GIRepository, GLib # type: ignore
from . import typelib, xml_reader from . import typelib, xml_reader
from .errors import CompileError, CompilerBugError from .errors import CompileError, CompilerBugError
@ -64,11 +65,13 @@ def collect_gir_search_paths():
if _gir_search_paths_initalized: if _gir_search_paths_initalized:
return return
global _gir_search_paths base_paths = [
if data_paths := os.environ.get("XDG_DATA_DIRS"): GLib.get_user_data_dir(),
_gir_search_paths += [ *GLib.get_system_data_dirs(),
os.path.join(path, "gir-1.0") for path in data_paths.split(os.pathsep)
] ]
global _gir_search_paths
_gir_search_paths = [os.path.join(path, "gir-1.0") for path in base_paths]
_gir_search_paths_initalized = True _gir_search_paths_initalized = True