Skip to content

Commit

Permalink
Prioritize config.yaml file locations properly
Browse files Browse the repository at this point in the history
  • Loading branch information
wthueb committed Aug 25, 2023
1 parent bda59ff commit 59930c0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions wi1_bot/config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import os
import pathlib
from typing import TypedDict

import yaml

_config_path: str | None = None

if os.path.isfile("config.yaml"):
_config_path = "config.yaml"
if home := os.getenv("HOME"):
_path = pathlib.Path(home) / ".config" / "wi1-bot" / "config.yaml"
if _path.is_file():
_config_path = str(_path.resolve())

if dir := os.getenv("XDG_CONFIG_HOME"):
if os.path.isfile(os.path.join(dir, "wi1-bot", "config.yaml")):
_config_path = os.path.join(dir, "wi1-bot", "config.yaml")
if xdg_config_home := os.getenv("XDG_CONFIG_HOME"):
_path = pathlib.Path(xdg_config_home) / "wi1-bot" / "config.yaml"
if _path.is_file():
_config_path = str(_path.resolve())

if home := os.getenv("HOME"):
if os.path.isfile(os.path.join(home, ".config", "wi1-bot", "config.yaml")):
_config_path = os.path.join(home, ".config", "wi1-bot", "config.yaml")
if pathlib.Path("config.yaml").is_file():
_config_path = "config.yaml"

if _config_path is None:
raise FileNotFoundError(
Expand Down

0 comments on commit 59930c0

Please sign in to comment.