Skip to content

Commit 58e5151

Browse files
committed
Decouple the Gramps core from GObject
1 parent 4bfd494 commit 58e5151

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

gramps/gen/const.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
import sys
3636
import uuid
3737

38-
from gi.repository import GLib
38+
try:
39+
from gi.repository import GLib
40+
41+
_GOBJECT_AVAILABLE = True
42+
except ModuleNotFoundError:
43+
_GOBJECT_AVAILABLE = False
3944

4045
# -------------------------------------------------------------------------
4146
#
@@ -119,7 +124,12 @@
119124
HOME_DIR = get_env_var("SAFEMODE")
120125

121126

122-
if os.path.exists(HOME_DIR) or "GRAMPSHOME" in os.environ or "SAFEMODE" in os.environ:
127+
if (
128+
os.path.exists(HOME_DIR)
129+
or "GRAMPSHOME" in os.environ
130+
or "SAFEMODE" in os.environ
131+
or not _GOBJECT_AVAILABLE
132+
):
123133
USER_DATA = HOME_DIR
124134
USER_CONFIG = HOME_DIR
125135
USER_CACHE = HOME_DIR
@@ -128,8 +138,11 @@
128138
USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps")
129139
USER_CACHE = os.path.join(GLib.get_user_cache_dir(), "gramps")
130140

131-
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
132-
if not USER_PICTURES:
141+
if _GOBJECT_AVAILABLE:
142+
USER_PICTURES = (
143+
GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) or HOME_DIR
144+
)
145+
else:
133146
USER_PICTURES = HOME_DIR
134147

135148
VERSION_DIR_NAME = "gramps%s%s" % (VERSION_TUPLE[0], VERSION_TUPLE[1])

gramps/gen/utils/requirements.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
# -------------------------------------------------------------------------
2626
from importlib.util import find_spec
2727

28-
# -------------------------------------------------------------------------
29-
#
30-
# GTK modules
31-
#
32-
# -------------------------------------------------------------------------
33-
import gi
34-
3528
# -------------------------------------------------------------------------
3629
#
3730
# Gramps modules
@@ -90,9 +83,11 @@ def _test_gi(self, module, version):
9083
Test to see if a particular version of a module is available.
9184
"""
9285
try:
86+
import gi
87+
9388
gi.require_version(module, version)
9489
return True
95-
except ValueError:
90+
except (ModuleNotFoundError, ValueError):
9691
return False
9792

9893
def check_exe(self, executable):

0 commit comments

Comments
 (0)