codeanalyzer-python 0.1.3__tar.gz → 0.1.5__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.3 → codeanalyzer_python-0.1.5}/.gitignore +4 -1
  2. codeanalyzer_python-0.1.5/PKG-INFO +392 -0
  3. codeanalyzer_python-0.1.5/README.md +373 -0
  4. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/__main__.py +53 -13
  5. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/core.py +5 -12
  6. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/schema/__init__.py +6 -6
  7. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/schema/py_schema.py +103 -125
  8. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/codeql/codeql_analysis.py +2 -2
  9. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/codeql/codeql_loader.py +3 -14
  10. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/codeql/codeql_query_runner.py +2 -1
  11. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/syntactic_analysis/symbol_table_builder.py +159 -162
  12. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/utils/__init__.py +1 -2
  13. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/utils/logging.py +2 -1
  14. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/utils/progress_bar.py +5 -4
  15. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/pyproject.toml +38 -7
  16. codeanalyzer_python-0.1.3/PKG-INFO +0 -198
  17. codeanalyzer_python-0.1.3/README.md +0 -176
  18. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/LICENSE +0 -0
  19. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/NOTICE +0 -0
  20. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/__init__.py +0 -0
  21. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/jedi/__init__.py +0 -0
  22. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/jedi/jedi.py +0 -0
  23. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/py.typed +0 -0
  24. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/__init__.py +0 -0
  25. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/codeql/__init__.py +2 -2
  26. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/codeql/codeql_exceptions.py +0 -0
  27. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/semantic_analysis/wala/__init__.py +0 -0
  28. {codeanalyzer_python-0.1.3 → codeanalyzer_python-0.1.5}/codeanalyzer/syntactic_analysis/__init__.py +0 -0
@@ -175,4 +175,7 @@ cython_debug/
175
175
 
176
176
  # Project-specific files
177
177
  .codeanalyzer
178
- .vscode/
178
+ .vscode/
179
+
180
+ # UV
181
+ uv.lock
@@ -0,0 +1,392 @@
1
+ Metadata-Version: 2.4
2
+ Name: codeanalyzer-python
3
+ Version: 0.1.5
4
+ Summary: Static Analysis on Python source code using Jedi, CodeQL and Treesitter.
5
+ Author-email: Rahul Krishna <i.m.ralk@gmail.com>
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: jedi>=0.19.2
10
+ Requires-Dist: loguru>=0.7.3
11
+ Requires-Dist: msgpack>=1.1.1
12
+ Requires-Dist: networkx>=3.5
13
+ Requires-Dist: pandas>=2.3.1
14
+ Requires-Dist: pydantic>=2.11.7
15
+ Requires-Dist: requests>=2.32.4
16
+ Requires-Dist: rich>=14.0.0
17
+ Requires-Dist: typer>=0.16.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
21
+
22
+ # A Python Static Analysis Toolkit (and Library)
23
+
24
+ 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.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install codeanalyzer-python
30
+ ```
31
+
32
+ ### Prerequisites
33
+
34
+ - Python 3.12 or higher
35
+
36
+ #### System Package Requirements
37
+
38
+ The tool creates virtual environments internally using Python's built-in `venv` module.
39
+
40
+ **Ubuntu/Debian systems:**
41
+ ```bash
42
+ sudo apt update
43
+ sudo apt install python3.12-venv python3-dev build-essential
44
+ ```
45
+
46
+ **Fedora/RHEL/CentOS systems:**
47
+ ```bash
48
+ sudo dnf group install "Development Tools"
49
+ sudo dnf install python3-pip python3-venv python3-devel
50
+ ```
51
+ or on older versions:
52
+ ```bash
53
+ sudo yum groupinstall "Development Tools"
54
+ sudo yum install python3-pip python3-venv python3-devel
55
+ ```
56
+
57
+ **macOS systems:**
58
+ ```bash
59
+ # Install Xcode Command Line Tools (for compilation)
60
+ xcode-select --install
61
+
62
+ # If using Homebrew Python (recommended)
63
+ brew install python@3.12
64
+
65
+ # If using pyenv (popular Python version manager)
66
+ # First ensure pyenv is properly installed and configured
67
+ pyenv install 3.12.0 # or latest 3.12.x version
68
+ pyenv global 3.12.0 # or pyenv local 3.12.0 for project-specific
69
+
70
+ # If using system Python, you may need to install certificates
71
+ /Applications/Python\ 3.12/Install\ Certificates.command
72
+ ```
73
+
74
+ > **Note:** These packages are required as the tool uses Python's built-in `venv` module to create isolated environments for analysis.
75
+
76
+ ## Usage
77
+
78
+ The codeanalyzer provides a command-line interface for performing static analysis on Python projects.
79
+
80
+ ### Basic Usage
81
+
82
+ ```bash
83
+ codeanalyzer --input /path/to/python/project
84
+ ```
85
+
86
+ ### Command Line Options
87
+
88
+ To view the available options and commands, run `codeanalyzer --help`. You should see output similar to the following:
89
+
90
+ ```bash
91
+ ❯ codeanalyzer --help
92
+
93
+ Usage: codeanalyzer [OPTIONS] COMMAND [ARGS]...
94
+
95
+ Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
96
+
97
+
98
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
99
+ │ * --input -i PATH Path to the project root directory. [default: None] [required] │
100
+ │ --output -o PATH Output directory for artifacts. [default: None] │
101
+ │ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
102
+ │ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
103
+ │ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
104
+ │ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
105
+ │ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
106
+ │ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
107
+ │ --help Show this message and exit. │
108
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
109
+ ```
110
+
111
+ ### Examples
112
+
113
+ 1. **Basic analysis with symbol table:**
114
+ ```bash
115
+ codeanalyzer --input ./my-python-project
116
+ ```
117
+
118
+ 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.
119
+
120
+ ```bash
121
+ codeanalyzer --input ./my-python-project --output /path/to/analysis-results
122
+ ```
123
+
124
+ Now, you can find the analysis results in `analysis.json` in the specified directory.
125
+
126
+ 2. **Toggle analysis levels with `--analysis-level`:**
127
+ ```bash
128
+ codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
129
+ ```
130
+ Call graph analysis can be enabled by setting the level to `2`:
131
+ ```bash
132
+ codeanalyzer --input ./my-python-project --analysis-level 2 # Symbol table + Call graph
133
+ ```
134
+ ***Note: The `--analysis-level=2` is not yet implemented in this version.***
135
+
136
+ 3. **Analysis with CodeQL enabled:**
137
+ ```bash
138
+ codeanalyzer --input ./my-python-project --codeql
139
+ ```
140
+ This will perform CodeQL-based analysis in addition to the standard symbol table generation.
141
+
142
+ ***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
143
+
144
+ 4. **Eager analysis with custom cache directory:**
145
+ ```bash
146
+ codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
147
+ ```
148
+ 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`.
149
+
150
+ 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`).
151
+
152
+ 5. **Quiet mode (minimal output):**
153
+ ```bash
154
+ codeanalyzer --input /path/to/my-python-project --quiet
155
+ ```
156
+
157
+ ### Output
158
+
159
+ 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.
160
+
161
+ ## Development
162
+
163
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management during development.
164
+
165
+ ### Development Setup
166
+
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
+ ```
355
+
356
+ 2. Clone the repository:
357
+ ```bash
358
+ git clone https://github.com/codellm-devkit/codeanalyzer-python
359
+ cd codeanalyzer-python
360
+ ```
361
+
362
+ 3. Install dependencies using uv:
363
+ ```bash
364
+ uv sync --all-groups
365
+ ```
366
+ This will install all dependencies including development and test dependencies.
367
+
368
+ ### Running from Source
369
+
370
+ When developing, you can run the tool directly from source:
371
+
372
+ ```bash
373
+ uv run codeanalyzer --input /path/to/python/project
374
+ ```
375
+
376
+ ### Running Tests
377
+
378
+ ```bash
379
+ uv run pytest --pspec -s
380
+ ```
381
+
382
+ ### Development Dependencies
383
+
384
+ The project includes additional dependency groups for development:
385
+
386
+ - **test**: pytest and related testing tools
387
+ - **dev**: development tools like ipdb
388
+
389
+ Install all groups with:
390
+ ```bash
391
+ uv sync --all-groups
392
+ ```