Coverage for session_buddy / utils / project_analysis.py: 100.00%
8 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-04 00:43 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-04 00:43 -0800
1"""Project analysis utilities.
3This module provides project structure and context analysis functions.
4Extracted to break circular dependencies between server_core and quality_engine.
5"""
7from __future__ import annotations
9from typing import TYPE_CHECKING
11if TYPE_CHECKING:
12 from pathlib import Path
15async def analyze_project_context(project_dir: Path) -> dict[str, bool]:
16 """Analyze project structure and context with enhanced error handling.
18 Args:
19 project_dir: Path to the project directory to analyze
21 Returns:
22 Dictionary with boolean flags for various project characteristics:
23 - python_project: Has pyproject.toml
24 - git_repo: Has .git directory
25 - has_tests: Has test files or directories
26 - has_docs: Has README.md or docs directory
27 - has_requirements: Has requirements.txt
28 - has_uv_lock: Has uv.lock file
29 - has_mcp_config: Has .mcp.json file
31 """
32 try:
33 # Ensure project_dir exists and is accessible
34 if not project_dir.exists():
35 return {
36 "python_project": False,
37 "git_repo": False,
38 "has_tests": False,
39 "has_docs": False,
40 "has_requirements": False,
41 "has_uv_lock": False,
42 "has_mcp_config": False,
43 }
45 return {
46 "python_project": (project_dir / "pyproject.toml").exists(),
47 "git_repo": (project_dir / ".git").exists(),
48 "has_tests": any(project_dir.glob("test*"))
49 or any(project_dir.glob("**/test*")),
50 "has_docs": (project_dir / "README.md").exists()
51 or any(project_dir.glob("docs/**")),
52 "has_requirements": (project_dir / "requirements.txt").exists(),
53 "has_uv_lock": (project_dir / "uv.lock").exists(),
54 "has_mcp_config": (project_dir / ".mcp.json").exists(),
55 }
56 except (OSError, PermissionError):
57 # Return safe defaults on error
58 return {
59 "python_project": False,
60 "git_repo": False,
61 "has_tests": False,
62 "has_docs": False,
63 "has_requirements": False,
64 "has_uv_lock": False,
65 "has_mcp_config": False,
66 }