File tree Expand file tree Collapse file tree
analysis/python/codeanalyzer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,7 +156,10 @@ def __init__(
156156 """
157157 if project_dir is None :
158158 raise ValueError ("project_dir is required for Python analysis." )
159- self .project_dir = Path (project_dir )
159+ # Expand ~ and resolve to absolute path for robustness
160+ self .project_dir = Path (project_dir ).expanduser ().resolve ()
161+ if not self .project_dir .is_dir ():
162+ raise ValueError (f"project_dir does not exist or is not a directory: { self .project_dir } " )
160163 self .analysis_level = analysis_level
161164 self .eager_analysis = eager_analysis
162165 self .target_files = target_files
@@ -165,8 +168,8 @@ def __init__(
165168 # codeanalyzer-python owns all caching. CLDK forwards these paths
166169 # verbatim; when cache_dir is None the backend defaults it to
167170 # <project_dir>/.codeanalyzer.
168- self .cache_dir = Path (cache_dir ) if cache_dir else None
169- self .analysis_json_path = Path (analysis_json_path ) if analysis_json_path else None
171+ self .cache_dir = Path (cache_dir ). expanduser (). resolve () if cache_dir else None
172+ self .analysis_json_path = Path (analysis_json_path ). expanduser (). resolve () if analysis_json_path else None
170173
171174 self .application : PyApplication = self ._run_analyzer ()
172175 # Class-signature → file path lookup, built once.
Original file line number Diff line number Diff line change @@ -192,6 +192,12 @@ def analysis(
192192 if project_path is not None and source_code is not None :
193193 raise CldkInitializationException ("Both project_path and source_code are provided. Please provide " "only one." )
194194
195+ # Normalize project_path: expand ~ and resolve to absolute path
196+ if project_path is not None :
197+ project_path = Path (project_path ).expanduser ().resolve ()
198+ if not project_path .is_dir ():
199+ raise CldkInitializationException (f"project_path does not exist or is not a directory: { project_path } " )
200+
195201 if self .language == "java" :
196202 return JavaAnalysis (
197203 project_dir = project_path ,
You can’t perform that action at this time.
0 commit comments