Skip to content

Commit 1c91e23

Browse files
authored
Merge pull request #153 from codellm-devkit/fix/tilde-expansion-in-project-path
fix: expand tilde (~) in project_path to prevent silent failures
2 parents 5d2a531 + 89a7b56 commit 1c91e23

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

cldk/analysis/python/codeanalyzer/codeanalyzer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def __init__(
8080
) -> None:
8181
if project_dir is None:
8282
raise ValueError("project_dir is required for Python analysis.")
83-
self.project_dir = Path(project_dir)
83+
# Expand ~ and resolve to absolute path for robustness
84+
self.project_dir = Path(project_dir).expanduser().resolve()
85+
if not self.project_dir.is_dir():
86+
raise ValueError(f"project_dir does not exist or is not a directory: {self.project_dir}")
8487
self.analysis_level = analysis_level
8588
self.eager_analysis = eager_analysis
8689
self.target_files = target_files
@@ -89,8 +92,8 @@ def __init__(
8992
# codeanalyzer-python owns all caching. CLDK forwards these paths
9093
# verbatim; when cache_dir is None the backend defaults it to
9194
# <project_dir>/.codeanalyzer.
92-
self.cache_dir = Path(cache_dir) if cache_dir else None
93-
self.analysis_json_path = Path(analysis_json_path) if analysis_json_path else None
95+
self.cache_dir = Path(cache_dir).expanduser().resolve() if cache_dir else None
96+
self.analysis_json_path = Path(analysis_json_path).expanduser().resolve() if analysis_json_path else None
9497

9598
self.application: PyApplication = self._run_analyzer()
9699
# Class-signature → file path lookup, built once.

cldk/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def analysis(
113113
if project_path is not None and source_code is not None:
114114
raise CldkInitializationException("Both project_path and source_code are provided. Please provide " "only one.")
115115

116+
# Normalize project_path: expand ~ and resolve to absolute path
117+
if project_path is not None:
118+
project_path = Path(project_path).expanduser().resolve()
119+
if not project_path.is_dir():
120+
raise CldkInitializationException(f"project_path does not exist or is not a directory: {project_path}")
121+
116122
if self.language == "java":
117123
return JavaAnalysis(
118124
project_dir=project_path,

0 commit comments

Comments
 (0)