codeanalyzer-python 0.1.9__tar.gz → 0.1.10__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.
- codeanalyzer_python-0.1.9/README.md → codeanalyzer_python-0.1.10/PKG-INFO +46 -17
- codeanalyzer_python-0.1.9/PKG-INFO → codeanalyzer_python-0.1.10/README.md +25 -36
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/__main__.py +40 -14
- codeanalyzer_python-0.1.10/codeanalyzer/core.py +599 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/schema/__init__.py +10 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/schema/py_schema.py +12 -3
- codeanalyzer_python-0.1.10/codeanalyzer/syntactic_analysis/__init__.py +16 -0
- codeanalyzer_python-0.1.10/codeanalyzer/syntactic_analysis/exceptions.py +15 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/syntactic_analysis/symbol_table_builder.py +104 -167
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/pyproject.toml +21 -18
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/LICENSE +191 -0
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/README.md +138 -0
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/properties/README.md +22 -0
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/xarray/datatree_/LICENSE +201 -0
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/xarray/datatree_/README.md +95 -0
- codeanalyzer_python-0.1.10/test/fixtures/whole_applications/xarray/xarray/datatree_/docs/README.md +14 -0
- codeanalyzer_python-0.1.9/codeanalyzer/core.py +0 -314
- codeanalyzer_python-0.1.9/codeanalyzer/syntactic_analysis/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/.gitignore +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/LICENSE +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/NOTICE +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/config/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/config/config.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/jedi/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/jedi/jedi.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/py.typed +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/codeql/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/codeql/codeql_analysis.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/codeql/codeql_exceptions.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/codeql/codeql_loader.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/codeql/codeql_query_runner.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/semantic_analysis/wala/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/utils/__init__.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/utils/logging.py +0 -0
- {codeanalyzer_python-0.1.9 → codeanalyzer_python-0.1.10}/codeanalyzer/utils/progress_bar.py +0 -0
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codeanalyzer-python
|
|
3
|
+
Version: 0.1.10
|
|
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.9
|
|
9
|
+
Requires-Dist: jedi<0.20.0,>=0.18.0
|
|
10
|
+
Requires-Dist: msgpack<1.0.7,>=1.0.0
|
|
11
|
+
Requires-Dist: networkx<3.2.0,>=2.6.0
|
|
12
|
+
Requires-Dist: numpy<1.24.0,>=1.21.0
|
|
13
|
+
Requires-Dist: pandas<2.0.0,>=1.3.0
|
|
14
|
+
Requires-Dist: pydantic<2.0.0,>=1.8.0
|
|
15
|
+
Requires-Dist: ray<3.0.0,>=2.0.0
|
|
16
|
+
Requires-Dist: requests<3.0.0,>=2.20.0
|
|
17
|
+
Requires-Dist: rich<14.0.0,>=12.6.0
|
|
18
|
+
Requires-Dist: typer<1.0.0,>=0.9.0
|
|
19
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
1
22
|

|
|
2
23
|
|
|
3
24
|
# A Python Static Analysis Toolkit (and Library)
|
|
@@ -76,17 +97,18 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
76
97
|
Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
|
|
77
98
|
|
|
78
99
|
|
|
79
|
-
╭─ Options
|
|
80
|
-
│ * --input -i PATH
|
|
81
|
-
│ --output -o PATH
|
|
82
|
-
│ --
|
|
83
|
-
│ --
|
|
84
|
-
│ --
|
|
85
|
-
│ --
|
|
86
|
-
│ --
|
|
87
|
-
│
|
|
88
|
-
│
|
|
89
|
-
|
|
100
|
+
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
|
101
|
+
│ * --input -i PATH Path to the project root directory. [default: None] [required] │
|
|
102
|
+
│ --output -o PATH Output directory for artifacts. [default: None] │
|
|
103
|
+
│ --format -f [json|msgpack] Output format: json or msgpack. [default: json] │
|
|
104
|
+
│ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
|
|
105
|
+
│ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
|
|
106
|
+
│ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
|
|
107
|
+
│ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
|
|
108
|
+
│ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
|
|
109
|
+
│ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
|
|
110
|
+
│ --help Show this message and exit. │
|
|
111
|
+
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
90
112
|
```
|
|
91
113
|
|
|
92
114
|
### Examples
|
|
@@ -104,7 +126,14 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
104
126
|
|
|
105
127
|
Now, you can find the analysis results in `analysis.json` in the specified directory.
|
|
106
128
|
|
|
107
|
-
2. **
|
|
129
|
+
2. **Change output format to msgpack:**
|
|
130
|
+
```bash
|
|
131
|
+
codeanalyzer --input ./my-python-project --output /path/to/analysis-results --format msgpack
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This will save the analysis results in `analysis.msgpack` in the specified directory.
|
|
135
|
+
|
|
136
|
+
3. **Toggle analysis levels with `--analysis-level`:**
|
|
108
137
|
```bash
|
|
109
138
|
codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
|
|
110
139
|
```
|
|
@@ -114,7 +143,7 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
114
143
|
```
|
|
115
144
|
***Note: The `--analysis-level=2` is not yet implemented in this version.***
|
|
116
145
|
|
|
117
|
-
|
|
146
|
+
4. **Analysis with CodeQL enabled:**
|
|
118
147
|
```bash
|
|
119
148
|
codeanalyzer --input ./my-python-project --codeql
|
|
120
149
|
```
|
|
@@ -122,7 +151,7 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
122
151
|
|
|
123
152
|
***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
|
|
124
153
|
|
|
125
|
-
|
|
154
|
+
5. **Eager analysis with custom cache directory:**
|
|
126
155
|
```bash
|
|
127
156
|
codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
|
|
128
157
|
```
|
|
@@ -130,14 +159,14 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
130
159
|
|
|
131
160
|
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
161
|
|
|
133
|
-
|
|
162
|
+
6. **Quiet mode (minimal output):**
|
|
134
163
|
```bash
|
|
135
164
|
codeanalyzer --input /path/to/my-python-project --quiet
|
|
136
165
|
```
|
|
137
166
|
|
|
138
|
-
|
|
167
|
+
## Output
|
|
139
168
|
|
|
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.
|
|
169
|
+
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. If you use the `--format=msgpack` option, the results will be saved in `analysis.msgpack`, which is a binary format that can be more efficient for storage and transmission.
|
|
141
170
|
|
|
142
171
|
## Development
|
|
143
172
|
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: codeanalyzer-python
|
|
3
|
-
Version: 0.1.9
|
|
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.10
|
|
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.4.2
|
|
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
1
|

|
|
21
2
|
|
|
22
3
|
# A Python Static Analysis Toolkit (and Library)
|
|
@@ -95,17 +76,18 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
95
76
|
Static Analysis on Python source code using Jedi, CodeQL and Tree sitter.
|
|
96
77
|
|
|
97
78
|
|
|
98
|
-
╭─ Options
|
|
99
|
-
│ * --input -i PATH
|
|
100
|
-
│ --output -o PATH
|
|
101
|
-
│ --
|
|
102
|
-
│ --
|
|
103
|
-
│ --
|
|
104
|
-
│ --
|
|
105
|
-
│ --
|
|
106
|
-
│
|
|
107
|
-
│
|
|
108
|
-
|
|
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
|
+
│ --format -f [json|msgpack] Output format: json or msgpack. [default: json] │
|
|
83
|
+
│ --analysis-level -a INTEGER 1: symbol table, 2: call graph. [default: 1] │
|
|
84
|
+
│ --codeql --no-codeql Enable CodeQL-based analysis. [default: no-codeql] │
|
|
85
|
+
│ --eager --lazy Enable eager or lazy analysis. Defaults to lazy. [default: lazy] │
|
|
86
|
+
│ --cache-dir -c PATH Directory to store analysis cache. [default: None] │
|
|
87
|
+
│ --clear-cache --keep-cache Clear cache after analysis. [default: clear-cache] │
|
|
88
|
+
│ -v INTEGER Increase verbosity: -v, -vv, -vvv [default: 0] │
|
|
89
|
+
│ --help Show this message and exit. │
|
|
90
|
+
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
109
91
|
```
|
|
110
92
|
|
|
111
93
|
### Examples
|
|
@@ -123,7 +105,14 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
123
105
|
|
|
124
106
|
Now, you can find the analysis results in `analysis.json` in the specified directory.
|
|
125
107
|
|
|
126
|
-
2. **
|
|
108
|
+
2. **Change output format to msgpack:**
|
|
109
|
+
```bash
|
|
110
|
+
codeanalyzer --input ./my-python-project --output /path/to/analysis-results --format msgpack
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
This will save the analysis results in `analysis.msgpack` in the specified directory.
|
|
114
|
+
|
|
115
|
+
3. **Toggle analysis levels with `--analysis-level`:**
|
|
127
116
|
```bash
|
|
128
117
|
codeanalyzer --input ./my-python-project --analysis-level 1 # Symbol table only
|
|
129
118
|
```
|
|
@@ -133,7 +122,7 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
133
122
|
```
|
|
134
123
|
***Note: The `--analysis-level=2` is not yet implemented in this version.***
|
|
135
124
|
|
|
136
|
-
|
|
125
|
+
4. **Analysis with CodeQL enabled:**
|
|
137
126
|
```bash
|
|
138
127
|
codeanalyzer --input ./my-python-project --codeql
|
|
139
128
|
```
|
|
@@ -141,7 +130,7 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
141
130
|
|
|
142
131
|
***Note: Not yet fully implemented. Please refrain from using this option until further notice.***
|
|
143
132
|
|
|
144
|
-
|
|
133
|
+
5. **Eager analysis with custom cache directory:**
|
|
145
134
|
```bash
|
|
146
135
|
codeanalyzer --input ./my-python-project --eager --cache-dir /path/to/custom-cache
|
|
147
136
|
```
|
|
@@ -149,14 +138,14 @@ To view the available options and commands, run `codeanalyzer --help`. You shoul
|
|
|
149
138
|
|
|
150
139
|
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
140
|
|
|
152
|
-
|
|
141
|
+
6. **Quiet mode (minimal output):**
|
|
153
142
|
```bash
|
|
154
143
|
codeanalyzer --input /path/to/my-python-project --quiet
|
|
155
144
|
```
|
|
156
145
|
|
|
157
|
-
|
|
146
|
+
## Output
|
|
158
147
|
|
|
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.
|
|
148
|
+
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. If you use the `--format=msgpack` option, the results will be saved in `analysis.msgpack`, which is a binary format that can be more efficient for storage and transmission.
|
|
160
149
|
|
|
161
150
|
## Development
|
|
162
151
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Optional, Annotated
|
|
3
3
|
|
|
4
4
|
import typer
|
|
5
5
|
|
|
@@ -7,7 +7,6 @@ from codeanalyzer.core import Codeanalyzer
|
|
|
7
7
|
from codeanalyzer.utils import _set_log_level, logger
|
|
8
8
|
from codeanalyzer.config import OutputFormat
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
def main(
|
|
12
11
|
input: Annotated[
|
|
13
12
|
Path, typer.Option("-i", "--input", help="Path to the project root directory.")
|
|
@@ -32,6 +31,12 @@ def main(
|
|
|
32
31
|
using_codeql: Annotated[
|
|
33
32
|
bool, typer.Option("--codeql/--no-codeql", help="Enable CodeQL-based analysis.")
|
|
34
33
|
] = False,
|
|
34
|
+
using_ray: Annotated[
|
|
35
|
+
bool,
|
|
36
|
+
typer.Option(
|
|
37
|
+
"--ray/--no-ray", help="Enable Ray for distributed analysis."
|
|
38
|
+
),
|
|
39
|
+
] = False,
|
|
35
40
|
rebuild_analysis: Annotated[
|
|
36
41
|
bool,
|
|
37
42
|
typer.Option(
|
|
@@ -39,18 +44,32 @@ def main(
|
|
|
39
44
|
help="Enable eager or lazy analysis. Defaults to lazy.",
|
|
40
45
|
),
|
|
41
46
|
] = False,
|
|
47
|
+
skip_tests: Annotated[
|
|
48
|
+
bool,
|
|
49
|
+
typer.Option(
|
|
50
|
+
"--skip-tests/--include-tests",
|
|
51
|
+
help="Skip test files in analysis.",
|
|
52
|
+
),
|
|
53
|
+
] = True,
|
|
54
|
+
file_name: Annotated[
|
|
55
|
+
Optional[Path],
|
|
56
|
+
typer.Option(
|
|
57
|
+
"--file-name",
|
|
58
|
+
help="Analyze only the specified file (relative to input directory).",
|
|
59
|
+
),
|
|
60
|
+
] = None,
|
|
42
61
|
cache_dir: Annotated[
|
|
43
62
|
Optional[Path],
|
|
44
63
|
typer.Option(
|
|
45
64
|
"-c",
|
|
46
65
|
"--cache-dir",
|
|
47
|
-
help="Directory to store analysis cache.",
|
|
66
|
+
help="Directory to store analysis cache. Defaults to '.codeanalyzer' in the input directory.",
|
|
48
67
|
),
|
|
49
68
|
] = None,
|
|
50
69
|
clear_cache: Annotated[
|
|
51
70
|
bool,
|
|
52
|
-
typer.Option("--clear-cache/--keep-cache", help="Clear cache after analysis."),
|
|
53
|
-
] =
|
|
71
|
+
typer.Option("--clear-cache/--keep-cache", help="Clear cache after analysis. By default, cache is retained."),
|
|
72
|
+
] = False,
|
|
54
73
|
verbosity: Annotated[
|
|
55
74
|
int, typer.Option("-v", count=True, help="Increase verbosity: -v, -vv, -vvv")
|
|
56
75
|
] = 0,
|
|
@@ -62,21 +81,28 @@ def main(
|
|
|
62
81
|
logger.error(f"Input path '{input}' does not exist.")
|
|
63
82
|
raise typer.Exit(code=1)
|
|
64
83
|
|
|
84
|
+
# Validate file_name if provided
|
|
85
|
+
if file_name is not None:
|
|
86
|
+
full_file_path = input / file_name
|
|
87
|
+
if not full_file_path.exists():
|
|
88
|
+
logger.error(f"Specified file '{file_name}' does not exist in '{input}'.")
|
|
89
|
+
raise typer.Exit(code=1)
|
|
90
|
+
if not full_file_path.is_file():
|
|
91
|
+
logger.error(f"Specified path '{file_name}' is not a file.")
|
|
92
|
+
raise typer.Exit(code=1)
|
|
93
|
+
if not str(file_name).endswith('.py'):
|
|
94
|
+
logger.error(f"Specified file '{file_name}' is not a Python file (.py).")
|
|
95
|
+
raise typer.Exit(code=1)
|
|
96
|
+
|
|
65
97
|
with Codeanalyzer(
|
|
66
|
-
input, analysis_level, using_codeql, rebuild_analysis, cache_dir, clear_cache
|
|
98
|
+
input, analysis_level, skip_tests, using_codeql, rebuild_analysis, cache_dir, clear_cache, using_ray, file_name
|
|
67
99
|
) as analyzer:
|
|
68
100
|
artifacts = analyzer.analyze()
|
|
69
101
|
|
|
70
102
|
# Handle output based on format
|
|
71
103
|
if output is None:
|
|
72
104
|
# Output to stdout (only for JSON)
|
|
73
|
-
|
|
74
|
-
print(artifacts.model_dump_json(separators=(",", ":")))
|
|
75
|
-
else:
|
|
76
|
-
logger.error(
|
|
77
|
-
f"Format '{format.value}' requires an output directory (use -o/--output)"
|
|
78
|
-
)
|
|
79
|
-
raise typer.Exit(code=1)
|
|
105
|
+
print(artifacts.json(separators=(",", ":")))
|
|
80
106
|
else:
|
|
81
107
|
# Output to file
|
|
82
108
|
output.mkdir(parents=True, exist_ok=True)
|
|
@@ -88,7 +114,7 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
|
|
|
88
114
|
if format == OutputFormat.JSON:
|
|
89
115
|
output_file = output_dir / "analysis.json"
|
|
90
116
|
# Use Pydantic's json() with separators for compact output
|
|
91
|
-
json_str = artifacts.
|
|
117
|
+
json_str = artifacts.json(indent=None)
|
|
92
118
|
with output_file.open("w") as f:
|
|
93
119
|
f.write(json_str)
|
|
94
120
|
logger.info(f"Analysis saved to {output_file}")
|