~reviewer/hello-hut

80fead3c8b8b3eaf0faa2694b6d88ad9ec31fd6e — Ines Moreau 5 months ago 689a417
config: do not crash when $HOME is unset

Fixes: https://todo.hut.md/~reviewer/hello-hut/5
2 files changed, 7 insertions(+), 1 deletions(-)

M docs/configuration.md
M src/hello_hut/config.py
M docs/configuration.md => docs/configuration.md +1 -0
@@ 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).

M src/hello_hut/config.py => src/hello_hut/config.py +6 -1
@@ 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")