Python Static Analysis Backend for CLDK
A comprehensive static analysis tool for Python source code that provides symbol table generation, call graph analysis, and semantic analysis using Jedi, CodeQL, and Tree-sitter.
This project uses uv for dependency management.
- uv installed
- Python 3.12 or higher. You can use
uvto install Python if it's not already installed:uv python install 3.12
-
Clone the repository:
git clone https://github.com/codellm-devkit/codeanalyzer-python cd codeanalyzer-python -
Install dependencies using uv:
uv sync --all-groups
This will install all dependencies including development and test dependencies.
The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
uv run codeanalyzer --input /path/to/python/projectTo view the available options and commands, run uv run codeanalyzer --help. You should see output similar to the following:
❯ uv run codeanalyzer --help Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]... Static Analysis on Python source code using Jedi, CodeQL and Tree sitter. ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ * --input -i PATH Path to the project root directory. [default: None] [required] │ │ --output -o PATH Output directory for artifacts. [default: None] │ │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │ │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │ │ --eager --lazy Enable eager or lazy analysis. Eager will rebuild the analysis cache at every run and lazy will use the cache if available. Defaults to lazy. [default: lazy] │ │ --cache-dir -c PATH Directory to store analysis cache. If not specified, the cache will be stored in the current working directory under `.codeanalyzer`. Defaults to None. [default: None] │ │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │ │ --verbose -v --quiet -q Enable verbose output. [default: v] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯-
Basic analysis with symbol table:
uv run codeanalyzer --input ./my-python-project
This will print the symbol table to stdout in JSON format to the standard output. If you want to save the output, you can use the
--outputoption.uv run codeanalyzer --input ./my-python-project --output /path/to/analysis-results
Now, you can find the analysis results in
analysis.jsonin the specified directory. -
Toggle analysis levels with
--analysis-level:uv run codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table onlyCall graph analysis can be enabled by setting the level to
2:uv run codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graphNote: The
--analysis-level=2is not yet implemented in this version. -
Analysis with CodeQL enabled:
uv run codeanalyzer --input ./my-python-project --codeql
This will perform CodeQL-based analysis in addition to the standard symbol table generation.
Note: Not yet fully implemented. Please refrain from using this option until further notice.
-
Eager analysis with custom cache directory:
uv run codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
This will rebuild the analysis cache at every run and store it in
/path/to/custom-cache/.codeanalyzer. The cache will be cleared by default after analysis unless you specify--keep-cache.If you provide --cache-dir, the cache will be stored in that directory. If not specified, it defaults to
.codeanalyzerin the current working directory ($PWD). -
Quiet mode (minimal output):
uv run codeanalyzer --input /path/to/my-python-project --quiet
By default, analysis results are printed to stdout in JSON format. When using the --output option, results are saved to analysis.json in the specified directory.
uv run pytest --pspec -s The project includes additional dependency groups for development:
- test: pytest and related testing tools
- dev: development tools like ipdb
Install all groups with:
uv sync --all-groups