Skip to content

Commit fb99bf7

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

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

gramps/gen/const.py

Lines changed: 10 additions & 4 deletions
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,8 @@
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(GLib.get_user_data_dir() if _GOBJECT_AVAILABLE else USER_HOME, "gramps")
126+
USER_CONFIG = os.path.join(GLib.get_user_config_dir() if _GOBJECT_AVAILABLE else USER_HOME, "gramps")
122127
# Copy the database directory into the XDG directory.
123128
OLD_HOME = os.path.join(USER_HOME, ".gramps")
124129
if os.path.exists(OLD_HOME):
@@ -134,7 +139,8 @@
134139
if "SAFEMODE" in os.environ:
135140
USER_CONFIG = get_env_var("SAFEMODE")
136141

137-
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
142+
if _GOBJECT_AVAILABLE:
143+
USER_PICTURES = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
138144
if not USER_PICTURES:
139145
USER_PICTURES = USER_DATA
140146

gramps/gen/utils/requirements.py

Lines changed: 3 additions & 8 deletions
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)