codeanalyzer-python 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

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.
codeanalyzer/__main__.py CHANGED
@@ -92,8 +92,10 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
92
92
  """Write artifacts to file in the specified format."""
93
93
  if format == OutputFormat.JSON:
94
94
  output_file = output_dir / "analysis.json"
95
+ # Use Pydantic's json() with separators for compact output
96
+ json_str = artifacts.model_dump_json(indent=None)
95
97
  with output_file.open("w") as f:
96
- f.write(artifacts.model_dump_json(separators=(",", ":")))
98
+ f.write(json_str)
97
99
  logger.info(f"Analysis saved to {output_file}")
98
100
 
99
101
  elif format == OutputFormat.MSGPACK:
@@ -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:
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeanalyzer-python
3
- Version: 0.1.4
3
+ Version: 0.1.5
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
8
  Requires-Python: >=3.12
9
- Requires-Dist: astor>=0.8.1
10
9
  Requires-Dist: jedi>=0.19.2
11
10
  Requires-Dist: loguru>=0.7.3
12
11
  Requires-Dist: msgpack>=1.1.1
@@ -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
@@ -1,5 +1,5 @@
1
1
  codeanalyzer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- codeanalyzer/__main__.py,sha256=JD8jukEzozZQlKZ2Cz08dZgWCDnM1d3VnZdbCoA-v0s,3830
2
+ codeanalyzer/__main__.py,sha256=xbBEltVa3ACC1tiQ7RWBoG7afkpuSv6RI8A3PpPGrII,3915
3
3
  codeanalyzer/core.py,sha256=29LVfRmprj6Y-f4rzwmdZ9dWH_S22zLo0Uqm_E62c5I,12431
4
4
  codeanalyzer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  codeanalyzer/jedi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -14,13 +14,13 @@ codeanalyzer/semantic_analysis/codeql/codeql_loader.py,sha256=o0BW-6yHkN6kLG66rO
14
14
  codeanalyzer/semantic_analysis/codeql/codeql_query_runner.py,sha256=QJtID1YZkO6Wyns_qTJFqOSiV238ArLXwgLv105B27E,6520
15
15
  codeanalyzer/semantic_analysis/wala/__init__.py,sha256=JSDvkrpJ2U90Ikex34EluSHmoGutlmRhV2xvInt6tB8,743
16
16
  codeanalyzer/syntactic_analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- codeanalyzer/syntactic_analysis/symbol_table_builder.py,sha256=kNNeLTw9Z24uDDTdDjWOgEiZ1JiWsZ4arSETvke44GU,36191
17
+ codeanalyzer/syntactic_analysis/symbol_table_builder.py,sha256=Q6AncS5MED8xrKHv5KQdtg2pnppyrXkoDSFOJ0y8FIA,36175
18
18
  codeanalyzer/utils/__init__.py,sha256=hC6VWdR5rerSqBxzu9KQHTASWqwrrYJv-CMDwrTlzkc,137
19
19
  codeanalyzer/utils/logging.py,sha256=0vTkGSl5EZN8yhhWa_5Mrn1n_twRCSW53rNwjzQ9RbI,601
20
20
  codeanalyzer/utils/progress_bar.py,sha256=ZHJzGiCo5q4dyXq4CtsrJeq9Ip7sD84T3yZjNX7TBys,2443
21
- codeanalyzer_python-0.1.4.dist-info/METADATA,sha256=rP6eR5doioj56UMBb_TkSXlPy2egh-ML3X4ydQ9mu6Q,7460
22
- codeanalyzer_python-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- codeanalyzer_python-0.1.4.dist-info/entry_points.txt,sha256=eUrB7Jq5Oav6RblMX_RYfVLSw_h15NbzC3fNSnGsPuM,59
24
- codeanalyzer_python-0.1.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- codeanalyzer_python-0.1.4.dist-info/licenses/NOTICE,sha256=YU0Z9NDWqKY-2jfFcbxeZ6fbnzz0oZeKmnUcO8a-bcQ,901
26
- codeanalyzer_python-0.1.4.dist-info/RECORD,,
21
+ codeanalyzer_python-0.1.5.dist-info/METADATA,sha256=-3mwXD07jkzG_4O1xjuuipDuA0wQuk52sHP9CSkxk2k,14458
22
+ codeanalyzer_python-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ codeanalyzer_python-0.1.5.dist-info/entry_points.txt,sha256=eUrB7Jq5Oav6RblMX_RYfVLSw_h15NbzC3fNSnGsPuM,59
24
+ codeanalyzer_python-0.1.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ codeanalyzer_python-0.1.5.dist-info/licenses/NOTICE,sha256=YU0Z9NDWqKY-2jfFcbxeZ6fbnzz0oZeKmnUcO8a-bcQ,901
26
+ codeanalyzer_python-0.1.5.dist-info/RECORD,,