Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cldk/analysis/python/codeanalyzer/codeanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def __init__(
) -> None:
if project_dir is None:
raise ValueError("project_dir is required for Python analysis.")
self.project_dir = Path(project_dir)
# Expand ~ and resolve to absolute path for robustness
self.project_dir = Path(project_dir).expanduser().resolve()
if not self.project_dir.is_dir():
raise ValueError(f"project_dir does not exist or is not a directory: {self.project_dir}")
self.analysis_level = analysis_level
self.eager_analysis = eager_analysis
self.target_files = target_files
Expand All @@ -89,8 +92,8 @@ def __init__(
# codeanalyzer-python owns all caching. CLDK forwards these paths
# verbatim; when cache_dir is None the backend defaults it to
# <project_dir>/.codeanalyzer.
self.cache_dir = Path(cache_dir) if cache_dir else None
self.analysis_json_path = Path(analysis_json_path) if analysis_json_path else None
self.cache_dir = Path(cache_dir).expanduser().resolve() if cache_dir else None
self.analysis_json_path = Path(analysis_json_path).expanduser().resolve() if analysis_json_path else None

self.application: PyApplication = self._run_analyzer()
# Class-signature → file path lookup, built once.
Expand Down
6 changes: 6 additions & 0 deletions cldk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def analysis(
if project_path is not None and source_code is not None:
raise CldkInitializationException("Both project_path and source_code are provided. Please provide " "only one.")

# Normalize project_path: expand ~ and resolve to absolute path
if project_path is not None:
project_path = Path(project_path).expanduser().resolve()
if not project_path.is_dir():
raise CldkInitializationException(f"project_path does not exist or is not a directory: {project_path}")

if self.language == "java":
return JavaAnalysis(
project_dir=project_path,
Expand Down