codeanalyzer-python 0.1.4__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/PKG-INFO +190 -4
  2. codeanalyzer_python-0.1.6/README.md +373 -0
  3. codeanalyzer_python-0.1.6/codeanalyzer/__init__.py +5 -0
  4. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/__main__.py +6 -9
  5. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/core.py +2 -2
  6. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/syntactic_analysis/symbol_table_builder.py +5 -4
  7. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/pyproject.toml +37 -5
  8. codeanalyzer_python-0.1.4/README.md +0 -186
  9. codeanalyzer_python-0.1.4/codeanalyzer/syntactic_analysis/__init__.py +0 -0
  10. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/.gitignore +0 -0
  11. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/LICENSE +0 -0
  12. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/NOTICE +0 -0
  13. {codeanalyzer_python-0.1.4/codeanalyzer → codeanalyzer_python-0.1.6/codeanalyzer/jedi}/__init__.py +0 -0
  14. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/jedi/jedi.py +0 -0
  15. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/py.typed +0 -0
  16. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/schema/__init__.py +0 -0
  17. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/schema/py_schema.py +0 -0
  18. {codeanalyzer_python-0.1.4/codeanalyzer/jedi → codeanalyzer_python-0.1.6/codeanalyzer/semantic_analysis}/__init__.py +0 -0
  19. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/codeql/__init__.py +0 -0
  20. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/codeql/codeql_analysis.py +0 -0
  21. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/codeql/codeql_exceptions.py +0 -0
  22. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/codeql/codeql_loader.py +0 -0
  23. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/codeql/codeql_query_runner.py +0 -0
  24. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/semantic_analysis/wala/__init__.py +0 -0
  25. {codeanalyzer_python-0.1.4/codeanalyzer/semantic_analysis → codeanalyzer_python-0.1.6/codeanalyzer/syntactic_analysis}/__init__.py +0 -0
  26. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/utils/__init__.py +0 -0
  27. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/utils/logging.py +0 -0
  28. {codeanalyzer_python-0.1.4 → codeanalyzer_python-0.1.6}/codeanalyzer/utils/progress_bar.py +0 -0
@@ -1,16 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeanalyzer-python
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Static Analysis on Python source code using Jedi, CodeQL and Treesitter.
5
5
  Author-email: Rahul Krishna <i.m.ralk@gmail.com>
6
6
  License-File: LICENSE
7
7
  License-File: NOTICE
8
- Requires-Python: >=3.12
9
- Requires-Dist: astor>=0.8.1
8
+ Requires-Python: ==3.10.*
10
9
  Requires-Dist: jedi>=0.19.2
11
10
  Requires-Dist: loguru>=0.7.3
12
11
  Requires-Dist: msgpack>=1.1.1
13
- Requires-Dist: networkx>=3.5
12
+ Requires-Dist: networkx>=3.4.2
14
13
  Requires-Dist: pandas>=2.3.1
15
14
  Requires-Dist: pydantic>=2.11.7
16
15
  Requires-Dist: requests>=2.32.4
@@ -166,6 +165,193 @@ This project uses [uv](https://docs.astral.sh/uv/) for dependency management dur
166
165
  ### Development Setup
167
166
 
168
167
  1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
168
+ ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
169
+
170
+ # A Python Static Analysis Toolkit (and Library)
171
+
172
+ 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.
173
+
174
+ ## Installation
175
+
176
+ ```bash
177
+ pip install codeanalyzer-python
178
+ ```
179
+
180
+ ### Prerequisites
181
+
182
+ - Python 3.12 or higher
183
+
184
+ #### System Package Requirements
185
+
186
+ The tool creates virtual environments internally using Python's built-in `venv` module.
187
+
188
+ **Ubuntu/Debian systems:**
189
+ ```bash
190
+ sudo apt update
191
+ sudo apt install python3.12-venv python3-dev build-essential
192
+ ```
193
+
194
+ **Fedora/RHEL/CentOS systems:**
195
+ ```bash
196
+ sudo dnf group install "Development Tools"
197
+ sudo dnf install python3-pip python3-venv python3-devel
198
+ ```
199
+ or on older versions:
200
+ ```bash
201
+ sudo yum groupinstall "Development Tools"
202
+ sudo yum install python3-pip python3-venv python3-devel
203
+ ```
204
+
205
+ **macOS systems:**
206
+ ```bash
207
+ # Install Xcode Command Line Tools (for compilation)
208
+ xcode-select --install
209
+
210
+ # If using Homebrew Python (recommended)
211
+ brew install python@3.12
212
+
213
+ # If using pyenv (popular Python version manager)
214
+ # First ensure pyenv is properly installed and configured
215
+ pyenv install 3.12.0 # or latest 3.12.x version
216
+ pyenv global 3.12.0 # or pyenv local 3.12.0 for project-specific
217
+
218
+ # If using system Python, you may need to install certificates
219
+ /Applications/Python\ 3.12/Install\ Certificates.command
220
+ ```
221
+
222
+ > **Note:** These packages are required as the tool uses Python's built-in `venv` module to create isolated environments for analysis.
223
+
224
+ ## Usage
225
+
226
+ The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
227
+
228
+ ### Basic Usage
229
+
230
+ ```bash
231
+ codeanalyzer --input /path/to/python/project
232
+ ```
233
+
234
+ ### Command Line Options
235
+
236
+ To view the available options and commands, run `codeanalyzer --help`. You should see output similar to the following:
237
+
238
+ ```bash
239
+ ❯ codeanalyzer --help
240
+
241
+ Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]...
242
+
243
+ Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
244
+
245
+
246
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
247
+ │ * --input -i PATH Path to the project root directory. [default: None] [required] │
248
+ │ --output -o PATH Output directory for artifacts. [default: None] │
249
+ │ --format -f [json|msgpack] Output format: json or msgpack. [default: json]. │
250
+ │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
251
+ │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
252
+ │ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
253
+ │ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
254
+ │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
255
+ │ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
256
+ │ --help Show this message and exit. │
257
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
258
+ ```
259
+
260
+ ### Examples
261
+
262
+ 1. **Basic analysis with symbol table:**
263
+ ```bash
264
+ codeanalyzer --input ./my-python-project
265
+ ```
266
+
267
+ 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 `--output` option.
268
+
269
+ ```bash
270
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results
271
+ ```
272
+
273
+ Now, you can find the analysis results in `analysis.json` in the specified directory.
274
+
275
+ 2. **Toggle analysis levels with `--analysis-level`:**
276
+ ```bash
277
+ codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
278
+ ```
279
+ Call graph analysis can be enabled by setting the level to `2`:
280
+ ```bash
281
+ codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graph
282
+ ```
283
+ ***Note: The `--analysis-level=2` is not yet implemented in this version.***
284
+
285
+ 3. **Analysis with CodeQL enabled:**
286
+ ```bash
287
+ codeanalyzer --input ./my-python-project --codeql
288
+ ```
289
+ This will perform CodeQL-based analysis in addition to the standard symbol table generation.
290
+
291
+ ***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
292
+
293
+ 4. **Eager analysis with custom cache directory:**
294
+ ```bash
295
+ codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
296
+ ```
297
+ 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`.
298
+
299
+ If you provide --cache-dir, the cache will be stored in that directory. If not specified, it defaults to `.codeanalyzer` in the current working directory (`$PWD`).
300
+
301
+ 5. **Save output in msgpack format:**
302
+ ```bash
303
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results --format msgpack
304
+ ```
305
+
306
+ ### Output
307
+
308
+ 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.
309
+
310
+ ## Development
311
+
312
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management during development.
313
+
314
+ ### Development Setup
315
+
316
+ 1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
317
+
318
+ 2. Clone the repository:
319
+ ```bash
320
+ git clone https://github.com/codellm-devkit/codeanalyzer-python
321
+ cd codeanalyzer-python
322
+ ```
323
+
324
+ 3. Install dependencies using uv:
325
+ ```bash
326
+ uv sync --all-groups
327
+ ```
328
+ This will install all dependencies including development and test dependencies.
329
+
330
+ ### Running from Source
331
+
332
+ When developing, you can run the tool directly from source:
333
+
334
+ ```bash
335
+ uv run codeanalyzer --input /path/to/python/project
336
+ ```
337
+
338
+ ### Running Tests
339
+
340
+ ```bash
341
+ uv run pytest --pspec -s
342
+ ```
343
+
344
+ ### Development Dependencies
345
+
346
+ The project includes additional dependency groups for development:
347
+
348
+ - **test**: pytest and related testing tools
349
+ - **dev**: development tools like ipdb
350
+
351
+ Install all groups with:
352
+ ```bash
353
+ uv sync --all-groups
354
+ ```
169
355
 
170
356
  2. Clone the repository:
171
357
  ```bash
@@ -0,0 +1,373 @@
1
+ ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
2
+
3
+ # A Python Static Analysis Toolkit (and Library)
4
+
5
+ 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.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install codeanalyzer-python
11
+ ```
12
+
13
+ ### Prerequisites
14
+
15
+ - Python 3.12 or higher
16
+
17
+ #### System Package Requirements
18
+
19
+ The tool creates virtual environments internally using Python's built-in `venv` module.
20
+
21
+ **Ubuntu/Debian systems:**
22
+ ```bash
23
+ sudo apt update
24
+ sudo apt install python3.12-venv python3-dev build-essential
25
+ ```
26
+
27
+ **Fedora/RHEL/CentOS systems:**
28
+ ```bash
29
+ sudo dnf group install "Development Tools"
30
+ sudo dnf install python3-pip python3-venv python3-devel
31
+ ```
32
+ or on older versions:
33
+ ```bash
34
+ sudo yum groupinstall "Development Tools"
35
+ sudo yum install python3-pip python3-venv python3-devel
36
+ ```
37
+
38
+ **macOS systems:**
39
+ ```bash
40
+ # Install Xcode Command Line Tools (for compilation)
41
+ xcode-select --install
42
+
43
+ # If using Homebrew Python (recommended)
44
+ brew install python@3.12
45
+
46
+ # If using pyenv (popular Python version manager)
47
+ # First ensure pyenv is properly installed and configured
48
+ pyenv install 3.12.0 # or latest 3.12.x version
49
+ pyenv global 3.12.0 # or pyenv local 3.12.0 for project-specific
50
+
51
+ # If using system Python, you may need to install certificates
52
+ /Applications/Python\ 3.12/Install\ Certificates.command
53
+ ```
54
+
55
+ > **Note:** These packages are required as the tool uses Python's built-in `venv` module to create isolated environments for analysis.
56
+
57
+ ## Usage
58
+
59
+ The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
60
+
61
+ ### Basic Usage
62
+
63
+ ```bash
64
+ codeanalyzer --input /path/to/python/project
65
+ ```
66
+
67
+ ### Command Line Options
68
+
69
+ To view the available options and commands, run `codeanalyzer --help`. You should see output similar to the following:
70
+
71
+ ```bash
72
+ ❯ codeanalyzer --help
73
+
74
+ Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]...
75
+
76
+ Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
77
+
78
+
79
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
80
+ │ * --input -i PATH Path to the project root directory. [default: None] [required] │
81
+ │ --output -o PATH Output directory for artifacts. [default: None] │
82
+ │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
83
+ │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
84
+ │ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
85
+ │ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
86
+ │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
87
+ │ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
88
+ │ --help Show this message and exit. │
89
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
90
+ ```
91
+
92
+ ### Examples
93
+
94
+ 1. **Basic analysis with symbol table:**
95
+ ```bash
96
+ codeanalyzer --input ./my-python-project
97
+ ```
98
+
99
+ 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 `--output` option.
100
+
101
+ ```bash
102
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results
103
+ ```
104
+
105
+ Now, you can find the analysis results in `analysis.json` in the specified directory.
106
+
107
+ 2. **Toggle analysis levels with `--analysis-level`:**
108
+ ```bash
109
+ codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
110
+ ```
111
+ Call graph analysis can be enabled by setting the level to `2`:
112
+ ```bash
113
+ codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graph
114
+ ```
115
+ ***Note: The `--analysis-level=2` is not yet implemented in this version.***
116
+
117
+ 3. **Analysis with CodeQL enabled:**
118
+ ```bash
119
+ codeanalyzer --input ./my-python-project --codeql
120
+ ```
121
+ This will perform CodeQL-based analysis in addition to the standard symbol table generation.
122
+
123
+ ***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
124
+
125
+ 4. **Eager analysis with custom cache directory:**
126
+ ```bash
127
+ codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
128
+ ```
129
+ 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`.
130
+
131
+ If you provide --cache-dir, the cache will be stored in that directory. If not specified, it defaults to `.codeanalyzer` in the current working directory (`$PWD`).
132
+
133
+ 5. **Quiet mode (minimal output):**
134
+ ```bash
135
+ codeanalyzer --input /path/to/my-python-project --quiet
136
+ ```
137
+
138
+ ### Output
139
+
140
+ 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.
141
+
142
+ ## Development
143
+
144
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management during development.
145
+
146
+ ### Development Setup
147
+
148
+ 1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
149
+ ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
150
+
151
+ # A Python Static Analysis Toolkit (and Library)
152
+
153
+ 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.
154
+
155
+ ## Installation
156
+
157
+ ```bash
158
+ pip install codeanalyzer-python
159
+ ```
160
+
161
+ ### Prerequisites
162
+
163
+ - Python 3.12 or higher
164
+
165
+ #### System Package Requirements
166
+
167
+ The tool creates virtual environments internally using Python's built-in `venv` module.
168
+
169
+ **Ubuntu/Debian systems:**
170
+ ```bash
171
+ sudo apt update
172
+ sudo apt install python3.12-venv python3-dev build-essential
173
+ ```
174
+
175
+ **Fedora/RHEL/CentOS systems:**
176
+ ```bash
177
+ sudo dnf group install "Development Tools"
178
+ sudo dnf install python3-pip python3-venv python3-devel
179
+ ```
180
+ or on older versions:
181
+ ```bash
182
+ sudo yum groupinstall "Development Tools"
183
+ sudo yum install python3-pip python3-venv python3-devel
184
+ ```
185
+
186
+ **macOS systems:**
187
+ ```bash
188
+ # Install Xcode Command Line Tools (for compilation)
189
+ xcode-select --install
190
+
191
+ # If using Homebrew Python (recommended)
192
+ brew install python@3.12
193
+
194
+ # If using pyenv (popular Python version manager)
195
+ # First ensure pyenv is properly installed and configured
196
+ pyenv install 3.12.0 # or latest 3.12.x version
197
+ pyenv global 3.12.0 # or pyenv local 3.12.0 for project-specific
198
+
199
+ # If using system Python, you may need to install certificates
200
+ /Applications/Python\ 3.12/Install\ Certificates.command
201
+ ```
202
+
203
+ > **Note:** These packages are required as the tool uses Python's built-in `venv` module to create isolated environments for analysis.
204
+
205
+ ## Usage
206
+
207
+ The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
208
+
209
+ ### Basic Usage
210
+
211
+ ```bash
212
+ codeanalyzer --input /path/to/python/project
213
+ ```
214
+
215
+ ### Command Line Options
216
+
217
+ To view the available options and commands, run `codeanalyzer --help`. You should see output similar to the following:
218
+
219
+ ```bash
220
+ ❯ codeanalyzer --help
221
+
222
+ Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]...
223
+
224
+ Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
225
+
226
+
227
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
228
+ │ * --input -i PATH Path to the project root directory. [default: None] [required] │
229
+ │ --output -o PATH Output directory for artifacts. [default: None] │
230
+ │ --format -f [json|msgpack] Output format: json or msgpack. [default: json]. │
231
+ │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
232
+ │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
233
+ │ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
234
+ │ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
235
+ │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
236
+ │ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
237
+ │ --help Show this message and exit. │
238
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
239
+ ```
240
+
241
+ ### Examples
242
+
243
+ 1. **Basic analysis with symbol table:**
244
+ ```bash
245
+ codeanalyzer --input ./my-python-project
246
+ ```
247
+
248
+ 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 `--output` option.
249
+
250
+ ```bash
251
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results
252
+ ```
253
+
254
+ Now, you can find the analysis results in `analysis.json` in the specified directory.
255
+
256
+ 2. **Toggle analysis levels with `--analysis-level`:**
257
+ ```bash
258
+ codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
259
+ ```
260
+ Call graph analysis can be enabled by setting the level to `2`:
261
+ ```bash
262
+ codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graph
263
+ ```
264
+ ***Note: The `--analysis-level=2` is not yet implemented in this version.***
265
+
266
+ 3. **Analysis with CodeQL enabled:**
267
+ ```bash
268
+ codeanalyzer --input ./my-python-project --codeql
269
+ ```
270
+ This will perform CodeQL-based analysis in addition to the standard symbol table generation.
271
+
272
+ ***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
273
+
274
+ 4. **Eager analysis with custom cache directory:**
275
+ ```bash
276
+ codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
277
+ ```
278
+ 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`.
279
+
280
+ If you provide --cache-dir, the cache will be stored in that directory. If not specified, it defaults to `.codeanalyzer` in the current working directory (`$PWD`).
281
+
282
+ 5. **Save output in msgpack format:**
283
+ ```bash
284
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results --format msgpack
285
+ ```
286
+
287
+ ### Output
288
+
289
+ 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.
290
+
291
+ ## Development
292
+
293
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management during development.
294
+
295
+ ### Development Setup
296
+
297
+ 1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
298
+
299
+ 2. Clone the repository:
300
+ ```bash
301
+ git clone https://github.com/codellm-devkit/codeanalyzer-python
302
+ cd codeanalyzer-python
303
+ ```
304
+
305
+ 3. Install dependencies using uv:
306
+ ```bash
307
+ uv sync --all-groups
308
+ ```
309
+ This will install all dependencies including development and test dependencies.
310
+
311
+ ### Running from Source
312
+
313
+ When developing, you can run the tool directly from source:
314
+
315
+ ```bash
316
+ uv run codeanalyzer --input /path/to/python/project
317
+ ```
318
+
319
+ ### Running Tests
320
+
321
+ ```bash
322
+ uv run pytest --pspec -s
323
+ ```
324
+
325
+ ### Development Dependencies
326
+
327
+ The project includes additional dependency groups for development:
328
+
329
+ - **test**: pytest and related testing tools
330
+ - **dev**: development tools like ipdb
331
+
332
+ Install all groups with:
333
+ ```bash
334
+ uv sync --all-groups
335
+ ```
336
+
337
+ 2. Clone the repository:
338
+ ```bash
339
+ git clone https://github.com/codellm-devkit/codeanalyzer-python
340
+ cd codeanalyzer-python
341
+ ```
342
+
343
+ 3. Install dependencies using uv:
344
+ ```bash
345
+ uv sync --all-groups
346
+ ```
347
+ This will install all dependencies including development and test dependencies.
348
+
349
+ ### Running from Source
350
+
351
+ When developing, you can run the tool directly from source:
352
+
353
+ ```bash
354
+ uv run codeanalyzer --input /path/to/python/project
355
+ ```
356
+
357
+ ### Running Tests
358
+
359
+ ```bash
360
+ uv run pytest --pspec -s
361
+ ```
362
+
363
+ ### Development Dependencies
364
+
365
+ The project includes additional dependency groups for development:
366
+
367
+ - **test**: pytest and related testing tools
368
+ - **dev**: development tools like ipdb
369
+
370
+ Install all groups with:
371
+ ```bash
372
+ uv sync --all-groups
373
+ ```
@@ -0,0 +1,5 @@
1
+ """Python code analyzer library."""
2
+
3
+ from codeanalyzer.core import Codeanalyzer
4
+
5
+ __all__ = ["Codeanalyzer"]
@@ -1,16 +1,11 @@
1
1
  from pathlib import Path
2
2
  from typing import Annotated, Optional
3
- from enum import Enum
4
3
 
5
4
  import typer
6
5
 
7
- from codeanalyzer.core import AnalyzerCore
6
+ from codeanalyzer.core import Codeanalyzer
8
7
  from codeanalyzer.utils import _set_log_level, logger
9
-
10
-
11
- class OutputFormat(str, Enum):
12
- JSON = "json"
13
- MSGPACK = "msgpack"
8
+ from codeanalyzer.config import OutputFormat
14
9
 
15
10
 
16
11
  def main(
@@ -67,7 +62,7 @@ def main(
67
62
  logger.error(f"Input path '{input}' does not exist.")
68
63
  raise typer.Exit(code=1)
69
64
 
70
- with AnalyzerCore(
65
+ with Codeanalyzer(
71
66
  input, analysis_level, using_codeql, rebuild_analysis, cache_dir, clear_cache
72
67
  ) as analyzer:
73
68
  artifacts = analyzer.analyze()
@@ -92,8 +87,10 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
92
87
  """Write artifacts to file in the specified format."""
93
88
  if format == OutputFormat.JSON:
94
89
  output_file = output_dir / "analysis.json"
90
+ # Use Pydantic's json() with separators for compact output
91
+ json_str = artifacts.model_dump_json(indent=None)
95
92
  with output_file.open("w") as f:
96
- f.write(artifacts.model_dump_json(separators=(",", ":")))
93
+ f.write(json_str)
97
94
  logger.info(f"Analysis saved to {output_file}")
98
95
 
99
96
  elif format == OutputFormat.MSGPACK:
@@ -13,7 +13,7 @@ from codeanalyzer.syntactic_analysis.symbol_table_builder import SymbolTableBuil
13
13
  from codeanalyzer.utils import logger
14
14
 
15
15
 
16
- class AnalyzerCore:
16
+ class Codeanalyzer:
17
17
  """Core functionality for CodeQL analysis.
18
18
 
19
19
  Args:
@@ -196,7 +196,7 @@ class AnalyzerCore:
196
196
  f"a working Python interpreter that can create virtual environments."
197
197
  )
198
198
 
199
- def __enter__(self) -> "AnalyzerCore":
199
+ def __enter__(self) -> "Codeanalyzer":
200
200
  # If no virtualenv is provided, try to create one using requirements.txt or pyproject.toml
201
201
  venv_path = self.cache_dir / self.project_dir.name / "virtualenv"
202
202
  # Ensure the cache directory exists for this project
@@ -5,7 +5,6 @@ from io import StringIO
5
5
  from pathlib import Path
6
6
  from typing import Dict, List, Optional
7
7
 
8
- import astor
9
8
  import jedi
10
9
  from jedi.api import Script
11
10
  from jedi.api.project import Project
@@ -183,7 +182,7 @@ class SymbolTableBuilder:
183
182
  f"{script.path.__str__().replace('/', '.').replace('.py', '')}.{class_node.name}",
184
183
  )
185
184
 
186
- code: str = astor.to_source(class_node).strip()
185
+ code: str = ast.unparse(class_node).strip()
187
186
 
188
187
  py_class = (
189
188
  PyClass.builder()
@@ -243,7 +242,7 @@ class SymbolTableBuilder:
243
242
  child, "end_lineno", start_line + len(child.body)
244
243
  )
245
244
  code_start_line = child.body[0].lineno if child.body else start_line
246
- code = astor.to_source(child).strip()
245
+ code: str = ast.unparse(child).strip()
247
246
  decorators = [ast.unparse(d) for d in child.decorator_list]
248
247
 
249
248
  try:
@@ -504,7 +503,9 @@ class SymbolTableBuilder:
504
503
 
505
504
  return params
506
505
 
507
- def _accessed_symbols(self, fn_node: ast.FunctionDef, script: Script) -> List[str]:
506
+ def _accessed_symbols(
507
+ self, fn_node: ast.FunctionDef, script: Script
508
+ ) -> List[PySymbol]:
508
509
  """Analyzes the function body to extract all accessed symbols."""
509
510
  symbols = []
510
511
  for node in ast.walk(fn_node):
@@ -1,19 +1,18 @@
1
1
  [project]
2
2
  name = "codeanalyzer-python"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Static Analysis on Python source code using Jedi, CodeQL and Treesitter."
5
5
  readme = "README.md"
6
6
  authors = [
7
7
  { name = "Rahul Krishna", email = "i.m.ralk@gmail.com" }
8
8
  ]
9
- requires-python = ">=3.12"
9
+ requires-python = "==3.10.*"
10
10
 
11
11
  dependencies = [
12
- "astor>=0.8.1",
13
12
  "jedi>=0.19.2",
14
13
  "loguru>=0.7.3",
15
14
  "msgpack>=1.1.1",
16
- "networkx>=3.5",
15
+ "networkx>=3.4.2",
17
16
  "pandas>=2.3.1",
18
17
  "pydantic>=2.11.7",
19
18
  "requests>=2.32.4",
@@ -54,4 +53,37 @@ include = [
54
53
  ]
55
54
 
56
55
  [tool.pytest.ini_options]
57
- testpaths = ["tests"]
56
+ addopts = [
57
+ "-p", "coverage",
58
+ "--cov=codeanalyzer",
59
+ "--cov-report=html",
60
+ "--cov-report=term-missing",
61
+ "--cov-fail-under=40"
62
+ ]
63
+ testpaths = ["test"]
64
+
65
+ [tool.coverage.run]
66
+ source = ["codeanalyzer"]
67
+ branch = true
68
+ omit = [
69
+ "*/tests/*",
70
+ "*/test_*",
71
+ "*/__pycache__/*",
72
+ "*/venv/*",
73
+ "*/.venv/*",
74
+ "codeanalyzer/semantic_analysis/*"
75
+ ]
76
+
77
+ [tool.coverage.report]
78
+ precision = 2
79
+ show_missing = true
80
+ exclude_lines = [
81
+ "pragma: no cover",
82
+ "def __repr__",
83
+ "raise AssertionError",
84
+ "raise NotImplementedError",
85
+ "if __name__ == .__main__.:"
86
+ ]
87
+
88
+ [tool.coverage.html]
89
+ directory = "htmlcov"
@@ -1,186 +0,0 @@
1
- ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
2
-
3
- # A Python Static Analysis Toolkit (and Library)
4
-
5
- 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.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- pip install codeanalyzer-python
11
- ```
12
-
13
- ### Prerequisites
14
-
15
- - Python 3.12 or higher
16
-
17
- #### System Package Requirements
18
-
19
- The tool creates virtual environments internally using Python's built-in `venv` module.
20
-
21
- **Ubuntu/Debian systems:**
22
- ```bash
23
- sudo apt update
24
- sudo apt install python3.12-venv python3-dev build-essential
25
- ```
26
-
27
- **Fedora/RHEL/CentOS systems:**
28
- ```bash
29
- sudo dnf group install "Development Tools"
30
- sudo dnf install python3-pip python3-venv python3-devel
31
- ```
32
- or on older versions:
33
- ```bash
34
- sudo yum groupinstall "Development Tools"
35
- sudo yum install python3-pip python3-venv python3-devel
36
- ```
37
-
38
- **macOS systems:**
39
- ```bash
40
- # Install Xcode Command Line Tools (for compilation)
41
- xcode-select --install
42
-
43
- # If using Homebrew Python (recommended)
44
- brew install python@3.12
45
-
46
- # If using pyenv (popular Python version manager)
47
- # First ensure pyenv is properly installed and configured
48
- pyenv install 3.12.0 # or latest 3.12.x version
49
- pyenv global 3.12.0 # or pyenv local 3.12.0 for project-specific
50
-
51
- # If using system Python, you may need to install certificates
52
- /Applications/Python\ 3.12/Install\ Certificates.command
53
- ```
54
-
55
- > **Note:** These packages are required as the tool uses Python's built-in `venv` module to create isolated environments for analysis.
56
-
57
- ## Usage
58
-
59
- The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
60
-
61
- ### Basic Usage
62
-
63
- ```bash
64
- codeanalyzer --input /path/to/python/project
65
- ```
66
-
67
- ### Command Line Options
68
-
69
- To view the available options and commands, run `codeanalyzer --help`. You should see output similar to the following:
70
-
71
- ```bash
72
- ❯ codeanalyzer --help
73
-
74
- Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]...
75
-
76
- Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
77
-
78
-
79
- ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
80
- │ * --input -i PATH Path to the project root directory. [default: None] [required] │
81
- │ --output -o PATH Output directory for artifacts. [default: None] │
82
- │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
83
- │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
84
- │ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
85
- │ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
86
- │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
87
- │ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
88
- │ --help Show this message and exit. │
89
- ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
90
- ```
91
-
92
- ### Examples
93
-
94
- 1. **Basic analysis with symbol table:**
95
- ```bash
96
- codeanalyzer --input ./my-python-project
97
- ```
98
-
99
- 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 `--output` option.
100
-
101
- ```bash
102
- codeanalyzer --input ./my-python-project --output /path/to/analysis-results
103
- ```
104
-
105
- Now, you can find the analysis results in `analysis.json` in the specified directory.
106
-
107
- 2. **Toggle analysis levels with `--analysis-level`:**
108
- ```bash
109
- codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
110
- ```
111
- Call graph analysis can be enabled by setting the level to `2`:
112
- ```bash
113
- codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graph
114
- ```
115
- ***Note: The `--analysis-level=2` is not yet implemented in this version.***
116
-
117
- 3. **Analysis with CodeQL enabled:**
118
- ```bash
119
- codeanalyzer --input ./my-python-project --codeql
120
- ```
121
- This will perform CodeQL-based analysis in addition to the standard symbol table generation.
122
-
123
- ***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
124
-
125
- 4. **Eager analysis with custom cache directory:**
126
- ```bash
127
- codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
128
- ```
129
- 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`.
130
-
131
- If you provide --cache-dir, the cache will be stored in that directory. If not specified, it defaults to `.codeanalyzer` in the current working directory (`$PWD`).
132
-
133
- 5. **Quiet mode (minimal output):**
134
- ```bash
135
- codeanalyzer --input /path/to/my-python-project --quiet
136
- ```
137
-
138
- ### Output
139
-
140
- 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.
141
-
142
- ## Development
143
-
144
- This project uses [uv](https://docs.astral.sh/uv/) for dependency management during development.
145
-
146
- ### Development Setup
147
-
148
- 1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/)
149
-
150
- 2. Clone the repository:
151
- ```bash
152
- git clone https://github.com/codellm-devkit/codeanalyzer-python
153
- cd codeanalyzer-python
154
- ```
155
-
156
- 3. Install dependencies using uv:
157
- ```bash
158
- uv sync --all-groups
159
- ```
160
- This will install all dependencies including development and test dependencies.
161
-
162
- ### Running from Source
163
-
164
- When developing, you can run the tool directly from source:
165
-
166
- ```bash
167
- uv run codeanalyzer --input /path/to/python/project
168
- ```
169
-
170
- ### Running Tests
171
-
172
- ```bash
173
- uv run pytest --pspec -s
174
- ```
175
-
176
- ### Development Dependencies
177
-
178
- The project includes additional dependency groups for development:
179
-
180
- - **test**: pytest and related testing tools
181
- - **dev**: development tools like ipdb
182
-
183
- Install all groups with:
184
- ```bash
185
- uv sync --all-groups
186
- ```