Skip to content

Commit e748022

Browse files
committed
Decouple the Gramps core from GObject
1 parent ee111ce commit e748022

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

gramps/gen/const.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939

4040
LOG = logging.getLogger(".")
4141

42-
from gi.repository import GLib
42+
try:
43+
from gi.repository import GLib
44+
45+
_GOBJECT_AVAILABLE = True
46+
except ModuleNotFoundError:
47+
_GOBJECT_AVAILABLE = False
4348

4449
# -------------------------------------------------------------------------
4550
#
@@ -117,8 +122,12 @@
117122
shutil.move(OLD_HOME, USER_DATA)
118123
else:
119124
USER_HOME = get_env_var("HOME")
120-
USER_DATA = os.path.join(GLib.get_user_data_dir(), "gramps")
121-
USER_CONFIG = os.path.join(GLib.get_user_config_dir(), "gramps")
125+
USER_DATA = os.path.join(
126+
GLib.get_user_data_dir() if _GOBJECT_AVAILABLE else USER_HOME, "gramps"
127+
)
128+
USER_CONFIG = os.path.join(
129+
GLib.get_user_config_dir() if _GOBJECT_AVAILABLE else USER_HOME, "gramps"
130+
)
122131
# Copy the database directory into the XDG directory.
123132
OLD_HOME = os.path.join(USER_HOME, ".gramps")
124133
if os.path.exists(OLD_HOME):
@@ -134,7 +143,8 @@
134143
if "SAFEMODE" in os.environ:
135144
USER_CONFIG = get_env_var("SAFEMODE")
136145

137-
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
146+
if _GOBJECT_AVAILABLE:
147+
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
138148
if not USER_PICTURES:
139149
USER_PICTURES = USER_DATA
140150

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)