diff --git a/src/depcheck/utils/__init__.py b/src/depcheck/utils/__init__.py new file mode 100644 index 0000000..08fcc07 --- /dev/null +++ b/src/depcheck/utils/__init__.py @@ -0,0 +1,35 @@ +"""Utility functions for depcheck.""" + +import os +from pathlib import Path +from typing import Optional + + +def find_config_file(config_name: str = ".depcheck.yaml") -> Optional[Path]: + """Find configuration file in current directory or XDG config home.""" + current_dir = Path.cwd() + config_path = current_dir / config_name + if config_path.exists(): + return config_path + + xdg_config = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config") + xdg_config_path = Path(xdg_config) / "depcheck" / config_name + if xdg_config_path.exists(): + return xdg_config_path + + return None + + +def read_file_safe(path: Path) -> Optional[str]: + """Read file contents safely, return None on error.""" + try: + return path.read_text() + except (OSError, IOError): + return None + + +def parse_version_string(version: str) -> Optional[str]: + """Clean and normalize a version string.""" + version = version.strip() + version = version.lstrip("vV") + return version if version else None