From 1cb699820f5f9c63263194e1cb79f668e9b4e5b9 Mon Sep 17 00:00:00 2001 From: tech Date: Wed, 18 Mar 2026 13:48:37 +0800 Subject: [PATCH] feat: add get_default_config_path function Co-Authored-By: Claude Opus 4.6 --- src/zzpyjenkins/config.py | 16 ++++++++++++++++ tests/test_config.py | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/zzpyjenkins/config.py b/src/zzpyjenkins/config.py index 7d53278..db74475 100644 --- a/src/zzpyjenkins/config.py +++ b/src/zzpyjenkins/config.py @@ -1,5 +1,6 @@ """Configuration file handling.""" +import os from pathlib import Path import tomllib @@ -10,6 +11,21 @@ class ConfigError(Exception): 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: """Load and parse TOML config file.""" if not config_path.exists(): diff --git a/tests/test_config.py b/tests/test_config.py index ccaea51..f1b09a3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,7 +5,12 @@ import tempfile import pytest 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(): @@ -68,3 +73,11 @@ def test_get_server_config_missing_field(): with pytest.raises(ConfigError) as exc_info: get_server_config(config, "incomplete") 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)