3333from codeanalyzer .config import OutputFormat
3434from codeanalyzer .core import Codeanalyzer
3535from codeanalyzer .options import AnalysisOptions
36- from codeanalyzer .schema import model_dump_json , model_validate_json
36+ from codeanalyzer .schema import model_dump_json
3737
3838from cldk .analysis import AnalysisLevel
39- from cldk .analysis .python .codeanalyzer .cache import (
40- default_analysis_dir ,
41- default_backend_cache_dir ,
42- )
4339from cldk .models .python import (
4440 PyApplication ,
4541 PyCallEdge ,
@@ -59,17 +55,15 @@ class PyCodeanalyzer:
5955 Args:
6056 project_dir: Path to the Python project root.
6157 analysis_level: Analysis level (symbol_table or call_graph).
62- analysis_json_path: Directory to persist analysis.json. If the file
63- exists and ``eager_analysis`` is False, it is loaded instead of
64- re-running the analyzer. When omitted, a content-addressed
65- location under the CLDK cache root is used (see
66- :mod:`cldk.analysis.python.codeanalyzer.cache`).
67- eager_analysis: If True, always re-runs the analyzer even when a
68- cached analysis.json is available.
69- cache_dir: Cache directory for the analyzer's virtualenv and CodeQL
70- artifacts. Forwarded verbatim to ``AnalysisOptions.cache_dir``.
71- When omitted, a dependency-hash-keyed location under the CLDK
72- cache root is used so the virtualenv survives source edits.
58+ analysis_json_path: Forwarded verbatim to ``AnalysisOptions.output``.
59+ ``codeanalyzer-python`` owns all caching; CLDK neither reads nor
60+ writes its own analysis.json.
61+ eager_analysis: If True, forces the backend to rebuild its analysis
62+ (``AnalysisOptions.rebuild_analysis``) rather than reuse its cache.
63+ cache_dir: Cache home for ``codeanalyzer-python`` (its virtualenv,
64+ CodeQL database, and ``analysis_cache.json``). Forwarded verbatim
65+ to ``AnalysisOptions.cache_dir``. When None, the backend defaults
66+ it to ``<project_dir>/.codeanalyzer``.
7367 target_files: Optional single target file (relative to project_dir).
7468 When provided, only that file is analyzed.
7569 """
@@ -92,25 +86,13 @@ def __init__(
9286 self .target_files = target_files
9387 self .use_codeql = use_codeql
9488
95- # Cache locations. Explicit args win; otherwise fall back to the
96- # content-addressed CLDK cache (two independently-keyed tiers).
97- if cache_dir :
98- self .cache_dir = Path (cache_dir )
99- else :
100- self .cache_dir = default_backend_cache_dir (self .project_dir )
101- if analysis_json_path :
102- self .analysis_json_path = Path (analysis_json_path )
103- else :
104- self .analysis_json_path = default_analysis_dir (
105- self .project_dir , analysis_level , use_codeql , target_files
106- )
107- logger .info (
108- "CLDK cache — backend: %s | analysis: %s" ,
109- self .cache_dir ,
110- self .analysis_json_path ,
111- )
89+ # codeanalyzer-python owns all caching. CLDK forwards these paths
90+ # verbatim; when cache_dir is None the backend defaults it to
91+ # <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
11294
113- self .application : PyApplication = self ._load_or_run_analyzer ()
95+ self .application : PyApplication = self ._run_analyzer ()
11496 # Class-signature → file path lookup, built once.
11597 self ._class_to_file : Dict [str , str ] = {}
11698 for file_path , module in self .application .symbol_table .items ():
@@ -123,13 +105,8 @@ def __init__(
123105 self .call_graph = None
124106
125107 # ----------------------------------------------------------------- core
126- def _load_or_run_analyzer (self ) -> PyApplication :
127- """Load a cached analysis.json when available, else run the analyzer."""
128- cached_file = self .analysis_json_path / "analysis.json" if self .analysis_json_path else None
129- if cached_file and cached_file .exists () and not self .eager_analysis :
130- logger .info (f"Loading cached PyApplication from { cached_file } " )
131- return model_validate_json (PyApplication , cached_file .read_text ())
132-
108+ def _run_analyzer (self ) -> PyApplication :
109+ """Run codeanalyzer-python; the backend handles its own caching."""
133110 target_file = None
134111 if self .target_files :
135112 if len (self .target_files ) > 1 :
@@ -151,12 +128,7 @@ def _load_or_run_analyzer(self) -> PyApplication:
151128 )
152129
153130 with Codeanalyzer (options ) as analyzer :
154- app = analyzer .analyze ()
155-
156- if self .analysis_json_path is not None :
157- self .analysis_json_path .mkdir (parents = True , exist_ok = True )
158- (self .analysis_json_path / "analysis.json" ).write_text (model_dump_json (app , indent = None ))
159- return app
131+ return analyzer .analyze ()
160132
161133 @staticmethod
162134 def _build_call_graph (edges : List [PyCallEdge ]) -> nx .DiGraph :
0 commit comments