You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/backends.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ flowchart LR
20
20
This separation lets a single `analysis` API span languages. The SDK does not parse code itself; it invokes the appropriate backend, then maps the backend JSON onto typed models (`JApplication`, `PyModule`, and others). A backend that emits the canonical JSON makes its language available to the SDK with only binding work required. See [Add a language backend](/contributing/add-language-backend/).
21
21
22
22
<Asidetype="note"title="Backends are managed by the SDK">
23
-
The SDK manages the backend automatically: it downloads the Java JAR and provisions the Python analyzer in a virtualenv. These pages document the backend layer for readers who want to understand or contribute to it.
23
+
The SDK manages the backend automatically: each `codeanalyzer-*` backend binary ships with its packaged PyPI dependency (the JVM-free Java backend runs via `python -m codeanalyzer_java`; the TypeScript binary ships in `codeanalyzer-typescript`), and the Python analyzer is provisioned in a virtualenv. There is no separate JAR download or `analysis_backend_path` override. These pages document the backend layer for readers who want to understand or contribute to it.
24
24
</Aside>
25
25
26
26
This is the **backend** layer. For the SDKs that consume it, see the [SDKs overview](/reference/sdks/).
Copy file name to clipboardExpand all lines: src/content/docs/backends/codeanalyzer-java.mdx
+34-14Lines changed: 34 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ codeanalyzer-java is a **standalone JAR tool** that takes a Java project (or a s
18
18
-**Comments & Javadoc**: Extracted and positioned for each entity
19
19
-**Entry points**: Main methods and framework-identified entry points (REST endpoints, Struts actions)
20
20
21
-
The Python SDK invokes this JAR, parses the JSON, and wraps it in `JavaAnalysis`, so callers interact with an `analysis` object rather than the backend directly.
21
+
The Python SDK invokes this backend, parses the JSON, and wraps it in `JavaAnalysis`, so callers interact with an `analysis` object rather than the backend directly. The backend is a JVM-free binary that ships with the packaged `codeanalyzer-java` PyPI dependency and is run via `python -m codeanalyzer_java`; there is no separate JAR download or `analysis_backend_path` override.
The Python SDK (`JavaAnalysis`) automates JAR invocation:
332
+
The Python SDK (`JavaAnalysis`) automates backend invocation:
333
333
334
-
1.**JAR discovery**: If `analysis_backend_path` is not provided, searches the package resources for `codeanalyzer-*.jar` (bundled)
335
-
2.**Invocation**: Calls `java -jar codeanalyzer-*.jar -i <project> -a <level> -o <tmpdir>` (or reads from stdout)
334
+
1.**Backend discovery**: The JVM-free backend ships with the packaged `codeanalyzer-java` PyPI dependency and is run via `python -m codeanalyzer_java`. There is no `analysis_backend_path` override anymore.
335
+
2.**Invocation**: Calls the backend with `-i <project> -a <level> -o <cache_dir>` (or reads from stdout)
336
336
3.**JSON parsing**: Deserializes the output into Pydantic models (`JApplication`, `JType`, `JCallable`, etc.)
337
337
4.**Facade**: Wraps the models in `JavaAnalysis`, exposing query methods like `get_classes()`, `get_call_graph()`, `get_callers()`
analysis_backend_path="/path/to/jar/dir"# Optional: custom JAR location
354
352
)
355
353
```
356
354
357
-
To point at a custom JAR location (for example, a locally built version):
355
+
The old `CLDK(language="java").analysis(...)` form still works but is **deprecated**; prefer the `CLDK.java(...)` factory shown above. The `from cldk import CLDK` import is unchanged.
356
+
357
+
To control where analysis artifacts are cached, pass a backend config:
358
358
359
359
```python
360
-
analysis = CLDK(language="java").analysis(
360
+
from cldk importCLDK
361
+
from cldk.analysis import AnalysisLevel
362
+
from cldk.analysis.commons.backend_config import CodeAnalyzerConfig
`CLDK.java(...)` accepts `project_path`, `analysis_level`, `target_files`, and `eager`. The backend is selected by the **type** of the `backend=` config; for Java the only backend is the in-memory codeanalyzer (`CodeAnalyzerConfig`), so omit `backend=` for the default. Pass `backend=CodeAnalyzerConfig(cache_dir=...)` only to override where artifacts are cached. Caching is **on by default**; the cache root defaults to `<project>/.codeanalyzer` and artifacts are written under a language-keyed subdirectory (`<cache_dir>/java/`).
374
+
375
+
Java also accepts `source_code=...` for analyzing a single Java source string, but this is **deprecated**; prefer `project_path`.
376
+
377
+
```python
378
+
analysis =CLDK.java(source_code="public class Test {}") # deprecated; prefer project_path
379
+
```
380
+
381
+
Importtheconfigobjectsfrom:
382
+
383
+
```python
384
+
from cldk.analysis.commons.backend_config import CodeAnalyzerConfig
The CLI is intended for backend developers and direct analysis runs. CLDK SDK users invoke the backend indirectly through `CLDK(language="python").analysis(...)`, which manages the virtualenv and invokes the CLI internally.
177
+
The CLI is intended for backend developers and direct analysis runs. CLDK SDK users invoke the backend indirectly through `CLDK.python(...)`, which manages the virtualenv and runs the analysis internally.
178
178
</Aside>
179
179
180
180
### Options
@@ -233,7 +233,7 @@ Analyzes only `src/handlers.py`.
233
233
234
234
## How the SDK consumes it
235
235
236
-
A call to `CLDK(language="python").analysis(project_path="my_pkg")` in the Python SDK proceeds as follows:
236
+
A call to `CLDK.python(project_path="my_pkg")` in the Python SDK proceeds as follows:
237
237
238
238
1.**Virtualenv provisioning**: CLDK detects or installs `codeanalyzer-python` into a managed virtualenv in the cache directory (default: `<project_dir>/.codeanalyzer/venv`).
239
239
@@ -253,11 +253,12 @@ A call to `CLDK(language="python").analysis(project_path="my_pkg")` in the Pytho
253
253
```python
254
254
from cldk importCLDK
255
255
from cldk.analysis import AnalysisLevel
256
+
from cldk.analysis.commons.backend_config import PyCodeAnalyzerConfig
The backend is selected by the **type** of the `backend=` config passed to `CLDK.python(...)`:
288
+
289
+
-**In-memory codeanalyzer** (default): omit `backend=`, or pass `backend=PyCodeAnalyzerConfig(...)`. The Python-only call-graph knobs `use_codeql=...` and `use_ray=...` live on this config, as does `cache_dir=...`.
290
+
-**Read-only Neo4j**: pass `backend=Neo4jConnectionConfig(...)` to query a graph populated out of band (no local analysis is run).
291
+
292
+
```python
293
+
from cldk importCLDK
294
+
from cldk.analysis.commons.backend_config import (
295
+
PyCodeAnalyzerConfig,
296
+
Neo4jConnectionConfig,
297
+
)
298
+
299
+
# In-memory backend with Ray + custom cache directory
300
+
analysis =CLDK.python(
301
+
project_path="my_pkg",
302
+
backend=PyCodeAnalyzerConfig(
303
+
use_codeql=True,
304
+
use_ray=True,
305
+
cache_dir="/tmp/analysis-cache",
306
+
),
307
+
)
308
+
309
+
# Read-only Neo4j backend
310
+
analysis =CLDK.python(
311
+
project_path="my_pkg",
312
+
backend=Neo4jConnectionConfig(
313
+
uri="bolt://localhost:7687",
314
+
username="neo4j",
315
+
password="neo4j",
316
+
database=None,
317
+
application_name="my_pkg",
318
+
),
319
+
)
320
+
```
321
+
322
+
`Neo4jConnectionConfig` is importable from `cldk.analysis.commons.backend_config` (and also from `cldk.analysis.python.neo4j`).
323
+
324
+
`CLDK.python(...)` keeps the `project_path`, `analysis_level`, `target_files`, and `eager` keyword arguments. The old `CLDK(language="python").analysis(...)` form still works but is **deprecated**; prefer `CLDK.python(...)`. The `from cldk import CLDK` import is unchanged.
325
+
284
326
### Caching and virtualenv management
285
327
286
-
-**Cache location**: Stored in `cache_dir/.codeanalyzer/` (default: `<project_dir>/.codeanalyzer/`).
287
-
-**Virtualenv**: Auto-created at `.codeanalyzer/<project_name>/virtualenv/`. The backend installs dependencies from `requirements.txt`, `pyproject.toml`, `setup.py`, `Pipfile`, etc.
328
+
-**Cache location**: A single language-keyed `cache_dir` (default: `<project_dir>/.codeanalyzer`); Python artifacts live under `<cache_dir>/python/`. Set it via `backend=PyCodeAnalyzerConfig(cache_dir=...)`.
329
+
-**Virtualenv**: Auto-created under the cache directory. The backend installs dependencies from `requirements.txt`, `pyproject.toml`, `setup.py`, `Pipfile`, etc.
Copy file name to clipboardExpand all lines: src/content/docs/backends/codeanalyzer-ts.mdx
+40-7Lines changed: 40 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ The `cants` CLI is available from **PyPI** and **Homebrew**. Both distribute a p
56
56
</TabItem>
57
57
</Tabs>
58
58
59
-
The CLDK Python SDK depends on the PyPI package `codeanalyzer-typescript` to locate this backend; the package exposes `bin_path()`, which returns the path to the bundled binary.
59
+
The CLDK Python SDK depends on the PyPI package `codeanalyzer-typescript` to locate this backend; the package exposes `bin_path()`, which returns the path to the bundled binary. There is no `analysis_backend_path` argument. To override the binary out of band (for example, a locally built `cants`), set the `$CODEANALYZER_TS_BIN` environment variable to its path; this is the sole override.
60
60
61
61
<Asidetype="note">
62
62
The distributable is named **`codeanalyzer-typescript`** (the PyPI package and the Homebrew formula), but the command it installs on `PATH` is **`cants`**, the analyzer's binary name. Run `cants`, not `codeanalyzer-typescript`.
@@ -297,13 +297,13 @@ TypeScript includes several language-specific constructs that codeanalyzer-ts mo
297
297
298
298
## Python SDK integration
299
299
300
-
TypeScript support in the Python SDK is **in development**. Once available, TypeScript projects will be analyzable through the same `CLDK` analysis API as Python and Java:
300
+
TypeScript projects are analyzable through the same `CLDK` analysis API as Python and Java, via the `CLDK.typescript(...)` factory:
The codeanalyzer-ts backend is complete and production-ready. The Python SDK integration is in progress on the `add-typescript-support` branch.
318
-
</Aside>
316
+
The old `CLDK(language="typescript").analysis(...)` form still works but is **deprecated**; prefer `CLDK.typescript(...)`. The `from cldk import CLDK` import is unchanged.
317
+
318
+
### Choosing a backend
319
+
320
+
`CLDK.typescript(...)` keeps the `project_path`, `analysis_level`, `target_files`, and `eager` keyword arguments. The backend is selected by the **type** of the `backend=` config:
321
+
322
+
-**In-memory codeanalyzer** (default): omit `backend=`, or pass `backend=CodeAnalyzerConfig(cache_dir=...)` to override where artifacts are cached.
323
+
-**Read-only Neo4j**: pass `backend=Neo4jConnectionConfig(...)` to query a graph populated out of band.
324
+
325
+
```python
326
+
from cldk importCLDK
327
+
from cldk.analysis.commons.backend_config import (
`Neo4jConnectionConfig` is importable from `cldk.analysis.commons.backend_config` (and also from `cldk.analysis.typescript.neo4j`).
319
352
320
353
## Schema invariants
321
354
@@ -330,7 +363,7 @@ This ensures every call-graph edge points to a real symbol-table entry.
330
363
331
364
## Caching and incremental analysis
332
365
333
-
The analyzer maintains a cache under `<project>/.codeanalyzer/` (or `-c <dir>`), stamped with the analyzer version. The cache is invalidated on:
366
+
The analyzer maintains a cache under a single language-keyed `cache_dir` (default: `<project>/.codeanalyzer`), with TypeScript artifacts under `<cache_dir>/typescript/`, stamped with the analyzer version. Caching is **on by default**. From the SDK, set the cache root via `backend=CodeAnalyzerConfig(cache_dir=...)`; on the CLI, use `-c <dir>`. The cache is invalidated on:
334
367
- Analyzer version change
335
368
- Any source file modification (content hash mismatch)
0 commit comments