Some checks failed
tamq-ci / test (push) Failing after 36s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02f34-ead4-7a60-85cd-d7f08e22fa0e
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import tomllib
|
|
from pathlib import Path
|
|
|
|
|
|
def config_path() -> Path:
|
|
return Path(os.environ.get("TAMQ_CONFIG", Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "tamq" / "config.toml"))
|
|
|
|
|
|
def _setting(name: str) -> str | None:
|
|
path = config_path()
|
|
if not path.exists():
|
|
return None
|
|
try:
|
|
with path.open("rb") as stream:
|
|
value = tomllib.load(stream).get("tamq", {}).get(name)
|
|
return value if isinstance(value, str) else None
|
|
except (OSError, tomllib.TOMLDecodeError):
|
|
return None
|
|
|
|
|
|
def setting(name: str, default: str) -> str:
|
|
"""Read a scalar [tamq] setting, falling back to a stable default."""
|
|
return _setting(name) or default
|
|
|
|
|
|
def state_dir() -> Path:
|
|
return Path(os.environ.get("TAMQ_STATE_DIR", _setting("state_dir") or Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state")) / "tamq"))
|
|
|
|
|
|
def db_path() -> Path:
|
|
return state_dir() / "tamq.sqlite3"
|
|
|
|
|
|
def socket_path() -> Path:
|
|
return Path(os.environ.get("TAMQ_SOCKET", _setting("socket") or Path(os.environ.get("XDG_RUNTIME_DIR", "/tmp")) / "tamq.sock"))
|
|
|
|
|
|
def pid_path() -> Path:
|
|
return Path(os.environ.get("TAMQ_PIDFILE", _setting("pidfile") or Path(os.environ.get("XDG_RUNTIME_DIR", "/tmp")) / "tamq.pid"))
|
|
|
|
|
|
def lock_path() -> Path:
|
|
return Path(os.environ.get("TAMQ_LOCKFILE", _setting("lockfile") or Path(os.environ.get("XDG_RUNTIME_DIR", "/tmp")) / "tamq.lock"))
|