Skip to content

Commit 8d50ade

Browse files
committed
Update facade to explore use_codeql by default.
Signed-off-by: Rahul Krishna <rkrsn@ibm.com>
1 parent 435ea9c commit 8d50ade

5 files changed

Lines changed: 46 additions & 9 deletions

File tree

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,22 @@ Each language has a dedicated analysis backend implemented under `cldk.analysis.
204204

205205
#### Python
206206
- **Backend:** `cldk.analysis.python`
207-
- **Tools:** `codeanalyzer-python` (Jedi + optional CodeQL), Tree-sitter for source-level parsing
207+
- **Tools:** `codeanalyzer-python` (Jedi + CodeQL, default on), Tree-sitter for source-level parsing
208208
- **Capabilities:** Symbol table, call graph, class/method resolution, comments/docstrings
209209

210-
> **Note — analysis cache:** The first Python analysis run creates a
211-
> `.codeanalyzer/` directory in the project under analysis. It holds the
212-
> backend's virtualenv, the CodeQL database (when enabled), and the cached
213-
> `analysis.json`. It can be large and is environment-specific, so **add
214-
> `.codeanalyzer/` (and `.cldk-cache/` if you persist analysis JSON there)
215-
> to your `.gitignore`.** Both are already ignored in this repo.
210+
> **Note — analysis cache:** Analysis artifacts are cached under `~/.cldk`
211+
> (override with `$CLDK_CACHE_DIR`): the backend virtualenv and CodeQL
212+
> database under `~/.cldk/venvs/<dep_hash>/`, and `analysis.json` under
213+
> `~/.cldk/cache/<key>/`. **CodeQL is enabled by default**
214+
> (`use_codeql=True`), so the first analysis of a project builds a CodeQL
215+
> database and provisions the CodeQL CLI — expect a slow cold run; subsequent
216+
> runs on the same source tree are cache hits. Pass `use_codeql=False` for
217+
> Jedi-only analysis. The CodeQL flag is part of the analysis cache key, so
218+
> toggling it — or upgrading from a version that defaulted it off — triggers
219+
> a **one-time** rebuild under a new key (no stale data is served). If you
220+
> instead point `analysis_backend_path` / `analysis_json_path` inside a
221+
> project, add those directories to your `.gitignore` — they are large and
222+
> environment-specific.
216223
217224
#### C
218225
- **Backend:** `cldk.analysis.c`

cldk/analysis/python/codeanalyzer/codeanalyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
eager_analysis: bool,
8383
analysis_backend_path: Union[str, Path, None] = None,
8484
target_files: List[str] | None = None,
85-
use_codeql: bool = False,
85+
use_codeql: bool = True,
8686
) -> None:
8787
if project_dir is None:
8888
raise ValueError("project_dir is required for Python analysis.")

cldk/analysis/python/python_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
analysis_level: str,
6565
target_files: List[str] | None,
6666
eager_analysis: bool,
67-
use_codeql: bool = False,
67+
use_codeql: bool = True,
6868
) -> None:
6969
if project_dir is None:
7070
raise ValueError(

cldk/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def analysis(
6161
target_files: List[str] | None = None,
6262
analysis_backend_path: str | None = None,
6363
analysis_json_path: str | Path = None,
64+
use_codeql: bool = True,
6465
) -> JavaAnalysis | PythonAnalysis | CAnalysis:
6566
"""Initialize a language-specific analysis façade.
6667
@@ -72,6 +73,9 @@ def analysis(
7273
target_files (list[str] | None): Files to constrain analysis (optional).
7374
analysis_backend_path (str | None): Path to the analysis backend.
7475
analysis_json_path (str | Path | None): Path to persist analysis database.
76+
use_codeql (bool): Python only, default True. Augments Jedi-resolved
77+
call edges with CodeQL-resolved edges; set False for a faster,
78+
Jedi-only analysis. Ignored for other languages.
7579
7680
Returns:
7781
JavaAnalysis | PythonAnalysis | CAnalysis: Initialized analysis façade for the chosen language.
@@ -117,6 +121,7 @@ def analysis(
117121
analysis_json_path=analysis_json_path,
118122
target_files=target_files,
119123
eager_analysis=eager,
124+
use_codeql=use_codeql,
120125
)
121126
elif self.language == "c":
122127
return CAnalysis(project_dir=project_path)

tests/analysis/python/test_python_analysis.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,28 @@ def test_python_analysis_rejects_source_code_mode():
3535
def test_python_analysis_requires_inputs():
3636
with pytest.raises(CldkInitializationException):
3737
CLDK(language="python").analysis()
38+
39+
40+
def test_use_codeql_forwarded_through_facade(monkeypatch, tmp_path):
41+
"""Regression: CLDK.analysis() must forward use_codeql to the backend.
42+
43+
Previously the façade dropped the flag, making CodeQL-augmented edges
44+
unreachable through the public API (only Jedi-resolved edges returned).
45+
"""
46+
captured = {}
47+
48+
class FakeBackend:
49+
def __init__(self, **kwargs):
50+
captured.update(kwargs)
51+
52+
monkeypatch.setattr(
53+
"cldk.analysis.python.python_analysis.PyCodeanalyzer", FakeBackend
54+
)
55+
56+
CLDK(language="python").analysis(project_path=tmp_path, use_codeql=False)
57+
assert captured["use_codeql"] is False
58+
59+
# CodeQL is the default; the façade must not silently drop it.
60+
captured.clear()
61+
CLDK(language="python").analysis(project_path=tmp_path)
62+
assert captured["use_codeql"] is True

0 commit comments

Comments
 (0)