From 80fead3c8b8b3eaf0faa2694b6d88ad9ec31fd6e Mon Sep 17 00:00:00 2001 From: Ines Moreau Date: Tue, 19 May 2026 22:15:00 +0200 Subject: [PATCH] config: do not crash when $HOME is unset Fixes: https://todo.hut.md/~reviewer/hello-hut/5 --- docs/configuration.md | 1 + src/hello_hut/config.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index b8e2b06b3518c3be792d124c4c10668b4b804ea6..a651a754f7effa37c6688740008819863d347ab8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,5 +24,6 @@ shout = false versions it is ignored. - Unknown keys are ignored, so you will not recieve an error for a misspelt key. Double-check the spelling if a setting seems to have no effect. +- If neither `$XDG_CONFIG_HOME` nor `$HOME` is set, no file is read. See also: [installation](install.md). diff --git a/src/hello_hut/config.py b/src/hello_hut/config.py index 210194c578ef1964f3bbed8076c8fbc5f0e7ae45..25a7f357373962efd8b6a1a07affd623d5ed8568 100644 --- a/src/hello_hut/config.py +++ b/src/hello_hut/config.py @@ -9,7 +9,12 @@ except ModuleNotFoundError: # Python < 3.11 def config_path(): - base = os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.environ["HOME"], ".config") + base = os.environ.get("XDG_CONFIG_HOME") + if not base: + home = os.environ.get("HOME") + if not home: + return None + base = os.path.join(home, ".config") return os.path.join(base, "hello-hut", "config.toml")