From 68610a7dbabb30a788d99a1e9a1556aa578d1dcd Mon Sep 17 00:00:00 2001 From: James Westman Date: Tue, 28 Jun 2022 23:43:01 -0500 Subject: [PATCH] typelib: Use GIRepository to find typelib path --- blueprintcompiler/gir.py | 32 +++++--------------------------- docs/packaging.rst | 7 ++----- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index 2515ab1..2b09027 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -21,6 +21,10 @@ from functools import cached_property import typing as T import os, sys +import gi # type: ignore +gi.require_version("GIRepository", "2.0") +from gi.repository import GIRepository # type: ignore + from .errors import CompileError, CompilerBugError from . import typelib, xml_reader @@ -29,25 +33,7 @@ _xml_cache = {} def get_namespace(namespace, version): - from .main import LIBDIR, VERSION - search_paths = [] - if LIBDIR is not None: - search_paths.append(os.path.join(LIBDIR, "girepository-1.0")) - - # This is a fragile hack to make blueprint-compiler work uninstalled on - # most systems. - if VERSION == "uninstalled": - search_paths += [ - "/usr/lib/girepository-1.0", - "/usr/local/lib/girepository-1.0", - "/app/lib/girepository-1.0", - "/usr/lib64/girepository-1.0", - "/usr/local/lib64/girepository-1.0", - "/app/lib64/girepository-1.0", - ] - - if typelib_path := os.environ.get("GI_TYPELIB_PATH"): - search_paths.append(typelib_path) + search_paths = GIRepository.Repository.get_search_path() filename = f"{namespace}-{version}.typelib" @@ -76,14 +62,6 @@ def get_xml(namespace, version): from xml.etree import ElementTree search_paths = [] - # Same fragile hack as before - if VERSION == "uninstalled": - search_paths += [ - "/usr/share/gir-1.0", - "/usr/local/share/gir-1.0", - "/app/share/gir-1.0", - ] - if data_paths := os.environ.get("XDG_DATA_DIRS"): search_paths += [os.path.join(path, "gir-1.0") for path in data_paths.split(os.pathsep)] diff --git a/docs/packaging.rst b/docs/packaging.rst index b0cd4e8..4f248e6 100644 --- a/docs/packaging.rst +++ b/docs/packaging.rst @@ -21,17 +21,14 @@ Blueprint files can import GObject Introspection namespaces like this: To compile a blueprint file, ``.typelib`` files for all of the imported namespaces must be installed. All blueprint files must import Gtk 4.0, so ``Gtk-4.0.typelib`` is effectively a runtime dependency of blueprint-compiler. +blueprint-compiler also depends on pygobject, because it uses GIRepository +to determine the search path for typelib files. So, if a package uses blueprint-compiler, its build dependencies should include the typelib files for any namespaces imported in its blueprint files. (Note that many apps also have the same typelib files as runtime dependencies, separately from blueprint). -The search path for typelib files is defined by the -`libdir `_ that Meson -uses. Additional paths may be passed at runtime through the ``GI_TYPELIB_PATH`` -environment variable. - In addition, the blueprint language server uses ``.gir`` files to provide documentation on hover. Some distros package these files separately from the main package (e.g. in a ``-devel`` package). The language server will not crash