From 5d6c01affe5ae9a3ca978f7c42216e0ee5520a4c Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 18:27:14 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- src/config.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/config.py diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..41e7b5b --- /dev/null +++ b/src/config.py @@ -0,0 +1,51 @@ +"""Configuration management for Code Pattern Search CLI.""" + +import os +from pathlib import Path +from typing import Optional +from dataclasses import dataclass + + +@dataclass +class Config: + """Configuration settings for the CLI.""" + + cache_dir: Optional[Path] = None + cache_ttl: int = 3600 + token: Optional[str] = None + verbose: bool = False + default_repos: int = 10 + max_repos: int = 100 + request_timeout: int = 30 + rate_limit_retries: int = 3 + retry_backoff_factor: float = 0.5 + + def __post_init__(self) -> None: + """Post-initialization processing.""" + if self.cache_dir is None: + self.cache_dir = self._default_cache_dir() + + def _default_cache_dir(self) -> Path: + """Get default cache directory.""" + return Path.home() / ".cache" / "code-pattern-search" + + @classmethod + def from_env(cls) -> "Config": + """Create configuration from environment variables.""" + cache_dir = os.getenv("CPS_CACHE_DIR") + cache_ttl = os.getenv("CPS_CACHE_TTL") + + return cls( + cache_dir=Path(cache_dir) if cache_dir else None, + cache_ttl=int(cache_ttl) if cache_ttl else 3600, + token=os.getenv("GITHUB_TOKEN"), + ) + + def get_cache_dir(self) -> Path: + """Get the cache directory, creating it if necessary.""" + if self.cache_dir: + self.cache_dir.mkdir(parents=True, exist_ok=True) + return self.cache_dir + default_dir = self._default_cache_dir() + default_dir.mkdir(parents=True, exist_ok=True) + return default_dir