File size: 629 Bytes
9191802 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from __future__ import annotations
import sys
from pathlib import Path
import yaml
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
def load_config(path: str | Path) -> dict:
path = Path(path)
with path.open("r", encoding="utf-8") as handle:
config = yaml.safe_load(handle)
config["_config_dir"] = str(path.resolve().parent)
return config
def resolve_path(value: str, config: dict) -> Path:
path = Path(value).expanduser()
if path.is_absolute():
return path
return (Path(config["_config_dir"]).parent / path).resolve()
|