feat: add get_default_config_path function

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 13:48:37 +08:00
parent 03ba3dc88e
commit 1cb699820f
2 changed files with 30 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
"""Configuration file handling.""" """Configuration file handling."""
import os
from pathlib import Path from pathlib import Path
import tomllib import tomllib
@@ -10,6 +11,21 @@ class ConfigError(Exception):
pass pass
def get_default_config_path() -> Path:
"""Get the default config file path.
Returns:
Path to ~/.config/zzpyjenkins/config.toml
"""
xdg_config = os.environ.get("XDG_CONFIG_HOME")
if xdg_config:
config_dir = Path(xdg_config)
else:
config_dir = Path.home() / ".config"
return config_dir / "zzpyjenkins" / "config.toml"
def load_config(config_path: Path) -> dict: def load_config(config_path: Path) -> dict:
"""Load and parse TOML config file.""" """Load and parse TOML config file."""
if not config_path.exists(): if not config_path.exists():

View File

@@ -5,7 +5,12 @@ import tempfile
import pytest import pytest
from pathlib import Path from pathlib import Path
from zzpyjenkins.config import load_config, ConfigError, get_server_config from zzpyjenkins.config import (
load_config,
ConfigError,
get_server_config,
get_default_config_path,
)
def test_load_config_file_not_found(): def test_load_config_file_not_found():
@@ -68,3 +73,11 @@ def test_get_server_config_missing_field():
with pytest.raises(ConfigError) as exc_info: with pytest.raises(ConfigError) as exc_info:
get_server_config(config, "incomplete") get_server_config(config, "incomplete")
assert "password" in str(exc_info.value) assert "password" in str(exc_info.value)
def test_get_default_config_path():
"""Test default config path is correct."""
path = get_default_config_path()
assert path.name == "config.toml"
assert ".config" in str(path)
assert "zzpyjenkins" in str(path)