~reviewer/hello-hut

ref: 0417a6598d9c5864e131002fb459924ff861e475 hello-hut/src/hello_hut/config.py -rw-r--r-- 627 bytes
0417a659 — Sam Lindqvist Add a logo 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Optional user configuration in ~/.config/hello-hut/config.toml."""

import os

try:
    import tomllib
except ModuleNotFoundError:  # Python < 3.11
    tomllib = None


def config_path():
    base = os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.environ["HOME"], ".config")
    return os.path.join(base, "hello-hut", "config.toml")


def load_config(path=None):
    """Return the parsed configuration, or an empty dict if there is none."""
    path = path or config_path()
    if not path or tomllib is None or not os.path.exists(path):
        return {}
    with open(path, "rb") as f:
        return tomllib.load(f)