From ac70ea7403abebc895b3b60082842604156babfd Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 13 Nov 2024 00:48:16 +0200 Subject: [PATCH] Port to libgirepository-2.0 pygobject 3.52 has switched [1] to using libgirepository-2.0 which comes from glib itself now, rather than the 1.0 which came from gobject-introspection. This means that it fails to load the incompatible "GIRepository 2.0" and thus must be ported to 3.0 (which is provided by libgirepository-2.0). Migration guide is here [2] [1]: https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/320 [2]: https://docs.gtk.org/girepository/migrating-gi.html This commit adds suppport for importing with "gi.require_version("GIRepository", "3.0") and falling back to the existing "GIRepository 2.0" if not found. --- blueprintcompiler/gir.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index 30a5eaa..e54b849 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -24,8 +24,20 @@ from functools import cached_property import gi # type: ignore -gi.require_version("GIRepository", "2.0") -from gi.repository import GIRepository # type: ignore +try: + gi.require_version("GIRepository", "3.0") + from gi.repository import GIRepository # type: ignore + + _repo = GIRepository.Repository() +except ValueError: + # We can remove this once we can bump the minimum dependencies + # to glib 2.80 and pygobject 3.52 + # dependency('glib-2.0', version: '>= 2.80.0') + # dependency('girepository-2.0', version: '>= 2.80.0') + gi.require_version("GIRepository", "2.0") + from gi.repository import GIRepository # type: ignore + + _repo = GIRepository.Repository from . import typelib, xml_reader from .errors import CompileError, CompilerBugError @@ -42,7 +54,7 @@ def add_typelib_search_path(path: str): def get_namespace(namespace: str, version: str) -> "Namespace": - search_paths = [*GIRepository.Repository.get_search_path(), *_user_search_paths] + search_paths = [*_repo.get_search_path(), *_user_search_paths] filename = f"{namespace}-{version}.typelib" @@ -74,7 +86,7 @@ def get_available_namespaces() -> T.List[T.Tuple[str, str]]: return _available_namespaces search_paths: list[str] = [ - *GIRepository.Repository.get_search_path(), + *_repo.get_search_path(), *_user_search_paths, ]