summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-06-22 18:59:29 +0200
committerMartin Fischer <martin@push-f.com>2025-06-28 07:10:54 +0200
commit2b0edd86db9ccbbf2c946f74c840e9c0b87fa462 (patch)
tree269a7a37faf1de2b0179cd967fd1f57ff98ecbd1
parent84387f8a10f14131150eeb5c047382569af11f4d (diff)
fix: generate-inx-files failing with Nix
Fixes the following error when attempting to build the Nix package: python bin/generate-inx-files; Traceback (most recent call last): File "/build/inkstitch/bin/generate-inx-files", line 59, in <module> from lib.inx.generate import generate_inx_files File "/build/inkstitch/lib/inx/generate.py", line 6, in <module> from .extensions import generate_extension_inx_files File "/build/inkstitch/lib/inx/extensions.py", line 10, in <module> from ..commands import (COMMANDS, GLOBAL_COMMANDS, LAYER_COMMANDS, File "/build/inkstitch/lib/commands.py", line 16, in <module> from .i18n import N_, _ File "/build/inkstitch/lib/i18n.py", line 10, in <module> from .utils import cache, get_resource_dir File "/build/inkstitch/lib/utils/__init__.py", line 6, in <module> from . import cache as cache_module # Slight hack to allow cache to be imported for monkeypatching ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/build/inkstitch/lib/utils/cache.py", line 13, in <module> from lib.utils.settings import global_settings File "/build/inkstitch/lib/utils/settings.py", line 84, in <module> global_settings = GlobalSettings() ^^^^^^^^^^^^^^^^ File "/build/inkstitch/lib/utils/settings.py", line 48, in __init__ self.__settings_file = os.path.join(get_user_dir(), "settings.json") ^^^^^^^^^^^^^^ File "/build/inkstitch/lib/utils/paths.py", line 50, in get_user_dir os.makedirs(path) File "<frozen os>", line 215, in makedirs File "<frozen os>", line 215, in makedirs File "<frozen os>", line 225, in makedirs PermissionError: [Errno 13] Permission denied: '/homeless-shelter'
-rwxr-xr-xlib/utils/paths.py4
-rw-r--r--lib/utils/settings.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/utils/paths.py b/lib/utils/paths.py
index 3bc12c2a..542a0f2d 100755
--- a/lib/utils/paths.py
+++ b/lib/utils/paths.py
@@ -41,12 +41,12 @@ def get_resource_dir(name):
return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name))
-def get_user_dir(name=None):
+def get_user_dir(name=None, create=True):
try:
path = platformdirs.user_config_dir('inkstitch')
except ImportError:
path = os.path.expanduser('~/.inkstitch')
- if not os.path.exists(path):
+ if create and not os.path.exists(path):
os.makedirs(path)
if name is not None:
diff --git a/lib/utils/settings.py b/lib/utils/settings.py
index 42e6b233..28c52290 100644
--- a/lib/utils/settings.py
+++ b/lib/utils/settings.py
@@ -45,7 +45,11 @@ DEFAULT_SETTINGS = {
class GlobalSettings(MutableMapping):
def __init__(self):
super().__init__()
- self.__settings_file = os.path.join(get_user_dir(), "settings.json")
+ # We set create=False here because this code is executed on module load
+ # and via imports also runs on generate-inx-files, which with the Nix
+ # package manager is executed with a non-writable home directory.
+ user_dir = get_user_dir(create=False)
+ self.__settings_file = os.path.join(user_dir, "settings.json")
self.__settings = {}
for name, value in DEFAULT_METADATA.items():