Coverage for src/workstack/cli/config.py: 100%
20 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
1import tomllib
2from dataclasses import dataclass
3from pathlib import Path
6@dataclass(frozen=True)
7class LoadedConfig:
8 """In-memory representation of `.workstack/config.toml`."""
10 env: dict[str, str]
11 post_create_commands: list[str]
12 post_create_shell: str | None
15def load_config(config_dir: Path) -> LoadedConfig:
16 """Load config.toml from the given directory if present; otherwise return defaults.
18 Example config:
19 [env]
20 DAGSTER_GIT_REPO_DIR = "{worktree_path}"
22 [post_create]
23 shell = "bash"
24 commands = [
25 "uv venv",
26 "uv run make dev_install",
27 ]
28 """
30 cfg_path = config_dir / "config.toml"
31 if not cfg_path.exists():
32 return LoadedConfig(env={}, post_create_commands=[], post_create_shell=None)
34 data = tomllib.loads(cfg_path.read_text(encoding="utf-8"))
35 env = {str(k): str(v) for k, v in data.get("env", {}).items()}
36 post = data.get("post_create", {})
37 commands = [str(x) for x in post.get("commands", [])]
38 shell = post.get("shell")
39 if shell is not None:
40 shell = str(shell)
41 return LoadedConfig(env=env, post_create_commands=commands, post_create_shell=shell)