[gobject-introspection/wip/smcv/search-paths: 6/6] Search XDG_DATA_HOME/gir-1.0 for GIR XML too
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/smcv/search-paths: 6/6] Search XDG_DATA_HOME/gir-1.0 for GIR XML too
- Date: Fri, 12 Feb 2021 10:54:27 +0000 (UTC)
commit af3c5d534bea659ab1255cd3dc814da4006deef5
Author: Simon McVittie <smcv debian org>
Date: Wed Feb 10 12:07:56 2021 +0000
Search XDG_DATA_HOME/gir-1.0 for GIR XML too
There probably won't be any, but the XDG base directory specification
is most useful if it's consistently followed everywhere, and the
specification says to look in XDG_DATA_HOME before XDG_DATA_DIRS.
Signed-off-by: Simon McVittie <smcv debian org>
Gbp-Pq: Name Search-XDG_DATA_HOME-gir-1.0-for-GIR-XML-too.patch
girepository/girparser.c | 5 +++++
giscanner/transformer.py | 3 +++
giscanner/utils.py | 30 ++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+)
---
diff --git a/girepository/girparser.c b/girepository/girparser.c
index 1d9d3c6c..b19e6fea 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -316,6 +316,11 @@ locate_gir (GIrParser *parser,
}
}
+ path = g_build_filename (g_get_user_data_dir (), GIR_SUFFIX, girname, NULL);
+ if (g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+ return path;
+ g_free (path);
+
for (dir = datadirs; *dir; dir++)
{
path = g_build_filename (*dir, GIR_SUFFIX, girname, NULL);
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 8ac6e265..2b1d16f2 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -183,6 +183,9 @@ None."""
def _find_include(self, include):
searchdirs = self._includepaths[:]
searchdirs.extend(os.getenv('GI_GIR_PATH', '').split(os.pathsep))
+ user_data = utils.get_user_data_dir()
+ if user_data is not None:
+ searchdirs.append(os.path.join(user_data, 'gir-1.0'))
for path in utils.get_system_data_dirs():
searchdirs.append(os.path.join(path, 'gir-1.0'))
searchdirs.append(GIR_DIR)
diff --git a/giscanner/utils.py b/giscanner/utils.py
index 45807f17..5d805d8e 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -235,6 +235,36 @@ def get_user_cache_dir(dir=None):
return None
+def get_user_data_dir():
+ '''
+ This is a Python reimplemention of `g_get_user_data_dir()` because we don't want to
+ rely on the python-xdg package and we can't depend on GLib via introspection.
+ If any changes are made to that function they'll need to be copied here.
+ '''
+
+ xdg_data_home = os.environ.get('XDG_DATA_HOME')
+ if xdg_data_home is not None:
+ try:
+ os.makedirs(xdg_data_home, mode=0o700, exist_ok=True)
+ except EnvironmentError:
+ # Let's fall back to ~/.local/share below
+ pass
+ else:
+ return xdg_data_home
+
+ homedir = os.path.expanduser('~')
+ if homedir is not None:
+ datadir = os.path.join(homedir, '.local', 'share')
+ try:
+ os.makedirs(datadir, mode=0o700, exist_ok=True)
+ except EnvironmentError:
+ return None
+ else:
+ return datadir
+
+ return None
+
+
def get_system_data_dirs():
'''
This is a Python reimplemention of `g_get_system_data_dirs()` because we don't want to
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]