pycode-doctor 0.1.0__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.
- pycode_doctor-0.1.0.dist-info/METADATA +235 -0
- pycode_doctor-0.1.0.dist-info/RECORD +49 -0
- pycode_doctor-0.1.0.dist-info/WHEEL +4 -0
- pycode_doctor-0.1.0.dist-info/entry_points.txt +14 -0
- pycode_doctor-0.1.0.dist-info/licenses/LICENSE +21 -0
- python_doctor/__init__.py +8 -0
- python_doctor/__main__.py +5 -0
- python_doctor/analysis_request.py +37 -0
- python_doctor/analyzer_catalog.py +102 -0
- python_doctor/analyzers/__init__.py +56 -0
- python_doctor/analyzers/bandit_scanner.py +143 -0
- python_doctor/analyzers/basedpyright_analyzer.py +109 -0
- python_doctor/analyzers/cached.py +113 -0
- python_doctor/analyzers/dependency_vulns.py +261 -0
- python_doctor/analyzers/deptry_analyzer.py +150 -0
- python_doctor/analyzers/detect_secrets_analyzer.py +106 -0
- python_doctor/analyzers/mypy_checker.py +226 -0
- python_doctor/analyzers/radon_analyzer.py +165 -0
- python_doctor/analyzers/registry.py +71 -0
- python_doctor/analyzers/ruff.py +253 -0
- python_doctor/analyzers/typos_analyzer.py +82 -0
- python_doctor/analyzers/vulture_analyzer.py +159 -0
- python_doctor/cache.py +255 -0
- python_doctor/cli.py +538 -0
- python_doctor/config.py +89 -0
- python_doctor/dedup.py +126 -0
- python_doctor/dependencies/discovery.py +196 -0
- python_doctor/detection.py +314 -0
- python_doctor/diff.py +140 -0
- python_doctor/discovery.py +188 -0
- python_doctor/formatters/__init__.py +1 -0
- python_doctor/formatters/badge.py +44 -0
- python_doctor/formatters/human.py +414 -0
- python_doctor/formatters/json_fmt.py +26 -0
- python_doctor/mcp/__init__.py +10 -0
- python_doctor/mcp/installer.py +125 -0
- python_doctor/mcp/server.py +439 -0
- python_doctor/models.py +120 -0
- python_doctor/plan.py +115 -0
- python_doctor/progress.py +101 -0
- python_doctor/rules.py +352 -0
- python_doctor/runner.py +375 -0
- python_doctor/scoring/__init__.py +1 -0
- python_doctor/scoring/engine.py +379 -0
- python_doctor/skills/SKILL.md +416 -0
- python_doctor/skills/__init__.py +1 -0
- python_doctor/skills/agents.py +100 -0
- python_doctor/skills/installer.py +253 -0
- python_doctor/skills/rule_db.py +824 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pycode-doctor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, local-first CLI that gives your Python codebase a 0-100 health score
|
|
5
|
+
Project-URL: Homepage, https://github.com/nabroleonx/python-doctor
|
|
6
|
+
Project-URL: Documentation, https://nabroleonx.github.io/python-doctor/
|
|
7
|
+
Project-URL: Repository, https://github.com/nabroleonx/python-doctor.git
|
|
8
|
+
Project-URL: Issues, https://github.com/nabroleonx/python-doctor/issues
|
|
9
|
+
Author: Nabeel S. Qureshi
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agent,code-quality,health-check,linting,mcp,python,static-analysis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Classifier: Topic :: Software Development :: Testing
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: bandit>=1.8
|
|
27
|
+
Requires-Dist: click>=8.1
|
|
28
|
+
Requires-Dist: deptry>=0.14
|
|
29
|
+
Requires-Dist: mypy>=1.13
|
|
30
|
+
Requires-Dist: radon>=6.0
|
|
31
|
+
Requires-Dist: rich>=13.0
|
|
32
|
+
Requires-Dist: ruff>=0.8.0
|
|
33
|
+
Requires-Dist: vulture>=2.12
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-mock>=3.14; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
40
|
+
Provides-Extra: full
|
|
41
|
+
Requires-Dist: basedpyright>=1.38; extra == 'full'
|
|
42
|
+
Requires-Dist: detect-secrets>=1.5; extra == 'full'
|
|
43
|
+
Requires-Dist: httpx>=0.27; extra == 'full'
|
|
44
|
+
Requires-Dist: mcp>=1.0; extra == 'full'
|
|
45
|
+
Requires-Dist: typos>=1.44; extra == 'full'
|
|
46
|
+
Provides-Extra: mcp
|
|
47
|
+
Requires-Dist: mcp>=1.0; extra == 'mcp'
|
|
48
|
+
Provides-Extra: pyright
|
|
49
|
+
Requires-Dist: basedpyright>=1.38; extra == 'pyright'
|
|
50
|
+
Provides-Extra: quality-extra
|
|
51
|
+
Requires-Dist: typos>=1.44; extra == 'quality-extra'
|
|
52
|
+
Provides-Extra: secrets
|
|
53
|
+
Requires-Dist: detect-secrets>=1.5; extra == 'secrets'
|
|
54
|
+
Provides-Extra: vulns
|
|
55
|
+
Requires-Dist: httpx>=0.27; extra == 'vulns'
|
|
56
|
+
Description-Content-Type: text/markdown
|
|
57
|
+
|
|
58
|
+
# python-doctor
|
|
59
|
+
|
|
60
|
+
Fast, local-first Python code health checks with a single command.
|
|
61
|
+
|
|
62
|
+
`python-doctor` combines Ruff, mypy, Bandit, Radon, Vulture, and deptry into a
|
|
63
|
+
single 0-100 score with clear category breakdowns. It is designed to feel good
|
|
64
|
+
with `uvx` first.
|
|
65
|
+
|
|
66
|
+
## Quickstart
|
|
67
|
+
|
|
68
|
+
Run it with no install step:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
uvx python-doctor .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use the latest published version explicitly:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uvx python-doctor@latest .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For deeper optional scans:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
uvx --from 'python-doctor[full]' python-doctor .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Persistent install:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uv tool install python-doctor
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## What The Default Scan Includes
|
|
93
|
+
|
|
94
|
+
- Ruff for quality, security, complexity, and dead-code rule families
|
|
95
|
+
- mypy for type checking
|
|
96
|
+
- Bandit for security checks
|
|
97
|
+
- Radon for complexity metrics
|
|
98
|
+
- Vulture for dead code
|
|
99
|
+
- deptry for dependency hygiene
|
|
100
|
+
|
|
101
|
+
Optional extras add:
|
|
102
|
+
|
|
103
|
+
- `dependency-vulns` for OSV-backed dependency vulnerability scanning
|
|
104
|
+
- `detect-secrets` for secret scanning
|
|
105
|
+
- `basedpyright` as an optional type backend
|
|
106
|
+
- `typos` for spelling checks in source code
|
|
107
|
+
- MCP support
|
|
108
|
+
|
|
109
|
+
## Common Commands
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# fast feedback
|
|
113
|
+
python-doctor . --profile quick
|
|
114
|
+
|
|
115
|
+
# full default scan
|
|
116
|
+
python-doctor .
|
|
117
|
+
|
|
118
|
+
# include optional analyzers if installed
|
|
119
|
+
python-doctor . --profile full
|
|
120
|
+
|
|
121
|
+
# only score output
|
|
122
|
+
python-doctor . --score
|
|
123
|
+
|
|
124
|
+
# machine-readable output
|
|
125
|
+
python-doctor . --json
|
|
126
|
+
|
|
127
|
+
# analyze only selected categories
|
|
128
|
+
python-doctor . --only quality,types
|
|
129
|
+
|
|
130
|
+
# skip categories
|
|
131
|
+
python-doctor . --skip security,dead_code
|
|
132
|
+
|
|
133
|
+
# safe Ruff autofix, then rescan
|
|
134
|
+
python-doctor . --fix
|
|
135
|
+
|
|
136
|
+
# show remediation text inline
|
|
137
|
+
python-doctor . --show-fixes
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Why `src/python_doctor/`?
|
|
141
|
+
|
|
142
|
+
The package is intentionally laid out as `src/python_doctor/`.
|
|
143
|
+
|
|
144
|
+
- `python-doctor` is the distribution and CLI name
|
|
145
|
+
- `python_doctor` is the Python import package name
|
|
146
|
+
|
|
147
|
+
The `src/` layout prevents packaging and test mistakes where imports succeed
|
|
148
|
+
from the checkout but fail from the built wheel.
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
Zero-config by default. Customize in `pyproject.toml`:
|
|
153
|
+
|
|
154
|
+
```toml
|
|
155
|
+
[tool.python-doctor]
|
|
156
|
+
timeout = 60
|
|
157
|
+
|
|
158
|
+
[tool.python-doctor.weights]
|
|
159
|
+
quality = 25
|
|
160
|
+
types = 20
|
|
161
|
+
security = 20
|
|
162
|
+
complexity = 15
|
|
163
|
+
dead_code = 10
|
|
164
|
+
dependencies = 10
|
|
165
|
+
|
|
166
|
+
[tool.python-doctor.ignore]
|
|
167
|
+
rules = ["S101"]
|
|
168
|
+
files = ["tests/**", "migrations/**"]
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
See `docs/configuration.md` for the full reference.
|
|
172
|
+
|
|
173
|
+
## MCP Server
|
|
174
|
+
|
|
175
|
+
Expose health data to AI coding agents (Claude Code, Cursor, VS Code):
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
python-doctor install-mcp cursor
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
This registers python-doctor as an MCP server. Your AI agent can then call
|
|
182
|
+
tools like `analyze_code`, `explain_rule`, `get_score`, `suggest_fixes`, and
|
|
183
|
+
`check_diff`.
|
|
184
|
+
|
|
185
|
+
See `docs/mcp-server.md` for details.
|
|
186
|
+
|
|
187
|
+
## Plugins
|
|
188
|
+
|
|
189
|
+
Extend python-doctor with custom analyzers via entry points:
|
|
190
|
+
|
|
191
|
+
```toml
|
|
192
|
+
[project.entry-points."python_doctor.analyzers"]
|
|
193
|
+
my-analyzer = "my_package:MyAnalyzer"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
See `docs/plugins.md` for the full guide.
|
|
197
|
+
|
|
198
|
+
## Output Model
|
|
199
|
+
|
|
200
|
+
The score covers six categories:
|
|
201
|
+
|
|
202
|
+
- quality
|
|
203
|
+
- type safety
|
|
204
|
+
- security
|
|
205
|
+
- complexity
|
|
206
|
+
- dead code
|
|
207
|
+
- dependencies
|
|
208
|
+
|
|
209
|
+
V1 also reports coverage, so a score can tell you whether the scan was full,
|
|
210
|
+
partial, or limited.
|
|
211
|
+
|
|
212
|
+
## Docs
|
|
213
|
+
|
|
214
|
+
Kept intentionally small:
|
|
215
|
+
|
|
216
|
+
- `docs/configuration.md` -- weights, thresholds, ignore rules
|
|
217
|
+
- `docs/scoring.md` -- scoring methodology
|
|
218
|
+
- `docs/mcp-server.md` -- MCP server setup
|
|
219
|
+
- `docs/plugins.md` -- custom analyzer development
|
|
220
|
+
- `docs/development.md` -- contributing to python-doctor
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
uv sync --all-extras
|
|
226
|
+
uv run pytest
|
|
227
|
+
uv run ruff check src tests
|
|
228
|
+
uv run mypy src
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
See `docs/development.md` for the full guide.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
python_doctor/__init__.py,sha256=GEmocznJ1GPmdotedvBkb8vb9tqWgtZZPIUArbQDPKw,233
|
|
2
|
+
python_doctor/__main__.py,sha256=TheTVeqS5jM_yHTR8-UDoGF7LZpa-LN9lZhbSGTioEA,94
|
|
3
|
+
python_doctor/analysis_request.py,sha256=hJ8zJL4-c0mFyBsTMHqwbQ6Wb2rAKW_J1XBl5QKNpsk,1078
|
|
4
|
+
python_doctor/analyzer_catalog.py,sha256=KYMrHnvBLyjQb50XeaHmI3-Szc-6g3vkoJcNcFB2G3M,2909
|
|
5
|
+
python_doctor/cache.py,sha256=8jKFX4UuufQLuzDJ4_aOikxA6V1v8JSGPeg8q0FijnQ,8599
|
|
6
|
+
python_doctor/cli.py,sha256=m-AE14ZTQXOUSCyOvjhNlY2kbeTG1xmaK0LYwzoVZlI,15315
|
|
7
|
+
python_doctor/config.py,sha256=nhDq7wEKgUDI6TWsZkTsRrLNBKaVaPr4uwXMDvbImiw,2716
|
|
8
|
+
python_doctor/dedup.py,sha256=ZJOzSFT51Ii9haR_BpNpnhJqjsjQLfG9kJbgXFjCWgs,3141
|
|
9
|
+
python_doctor/detection.py,sha256=ABjUd1kMwqn7bvqQOlGp1tIg7Z_qlLJqU-h_ukJCfKs,9143
|
|
10
|
+
python_doctor/diff.py,sha256=5jLvukNG63kQkimcjNw1KXoIf-ttj_8e4oujN-xQ-Nk,3937
|
|
11
|
+
python_doctor/discovery.py,sha256=Nw1GyM_H7X3U4QDcdAcSPaQdAn9IOsuw2M4YnGDrZlM,4938
|
|
12
|
+
python_doctor/models.py,sha256=0NNrKABPiWU0mZqjhBqxiS7tTgofFgXpr9Yy_2i3hww,3539
|
|
13
|
+
python_doctor/plan.py,sha256=Qlkl-tPooiQKqhX_vpn9pkkl5h7tukwMOTci8fCgNO0,3363
|
|
14
|
+
python_doctor/progress.py,sha256=xMJYrThZEB-YOfBk6nJl5ymkFYGRUHnF4D3O6kIbpMk,2983
|
|
15
|
+
python_doctor/rules.py,sha256=7ogCxVurBUN_dnyH2PvsV5vV8FluleVqJWG9Yq9rNHQ,13339
|
|
16
|
+
python_doctor/runner.py,sha256=1Q50IFu5vC8uL2vOwD76pzLLs9HFxjCoW9tPRREyiMk,13090
|
|
17
|
+
python_doctor/analyzers/__init__.py,sha256=MRpzQzzoQ1f2IjI805fM13iTXi547pjyLlgfMTssRNs,1592
|
|
18
|
+
python_doctor/analyzers/bandit_scanner.py,sha256=2wWwI06GykLPVV0wVlfbavfRN6tYUDupVt_Q2ggZREs,4030
|
|
19
|
+
python_doctor/analyzers/basedpyright_analyzer.py,sha256=nm6RNAWJIcT5VnkUBLkj1MCfkf5S4MN3LnPZzAjg8-k,3375
|
|
20
|
+
python_doctor/analyzers/cached.py,sha256=cU2wrnKzbm7ZCA1ivhdOhwya6CvnKl2GQnqeKfKS8cY,3684
|
|
21
|
+
python_doctor/analyzers/dependency_vulns.py,sha256=Ld_aRYQ-wlx9KnD31m9LC0gAQ-YI6pv2wFdCIYwOyUw,9585
|
|
22
|
+
python_doctor/analyzers/deptry_analyzer.py,sha256=jiKmpkRsHshcWiRfH8IHXnLEj-7zmaQa-wNYpIbk56o,4800
|
|
23
|
+
python_doctor/analyzers/detect_secrets_analyzer.py,sha256=IQPVIgAxz1Psg_pNldu6BMiKvvotTP2aDsySgAH3_Qc,3543
|
|
24
|
+
python_doctor/analyzers/mypy_checker.py,sha256=Amdwi_ea0AoZ23YNmjr_lEKRVdnYEYCkwuWD9tNqx1E,6916
|
|
25
|
+
python_doctor/analyzers/radon_analyzer.py,sha256=F9WZOI7ml9nulBNitXqlZ-G1xqJz357J2QHTA8-pcl8,5593
|
|
26
|
+
python_doctor/analyzers/registry.py,sha256=uId0xunYpKgmpv8Yf3p_v1LsBBF468cZvX1wLmcboP0,2350
|
|
27
|
+
python_doctor/analyzers/ruff.py,sha256=JP3OKcj3a7eqGdgr6fT5sXBnjHU9LfnRQKS9om5JSkY,7640
|
|
28
|
+
python_doctor/analyzers/typos_analyzer.py,sha256=Mp6Edf0K97G-dasvSjJ5iDoNdq4ZG9Oz4BWEgT_k5HY,2506
|
|
29
|
+
python_doctor/analyzers/vulture_analyzer.py,sha256=lyK4cbrVLm6Y1WOOzOd3nzAimE90GpA_k5jCxCFhi8Q,5102
|
|
30
|
+
python_doctor/dependencies/discovery.py,sha256=8mr_SNpWLNQ_ALXIArcRIhJYMQm-PtvWpH8YPQgDd-s,6172
|
|
31
|
+
python_doctor/formatters/__init__.py,sha256=2I9wUpnh-PwbhHCMGzN1UBkk8_h-VNymhWTU9_NeqX8,51
|
|
32
|
+
python_doctor/formatters/badge.py,sha256=-OVW7DrqSztpm52aCdsWIUsCPOdCSes_LnzeLbA1U6k,1205
|
|
33
|
+
python_doctor/formatters/human.py,sha256=YX3B5x3A3k-aueG93wuS3p4Mr20JtDXaGpTY3WPE-0I,12861
|
|
34
|
+
python_doctor/formatters/json_fmt.py,sha256=dEQf8nQZNZycME3nBoItvpV_xc6dhXTldECS5G2mXxw,675
|
|
35
|
+
python_doctor/mcp/__init__.py,sha256=C1lL_z6kdHTSFVkbA0a69r6iiPsUloO5_JnO3xQbxhc,311
|
|
36
|
+
python_doctor/mcp/installer.py,sha256=EP-jfnuTlQzucTRDQbWnLY8MBYznFcuLRBW2kh_QXaU,4014
|
|
37
|
+
python_doctor/mcp/server.py,sha256=WykSeuUytLWl5qGFRBZk7zxhQ4_BuiMJRgf_LmdJIUU,14092
|
|
38
|
+
python_doctor/scoring/__init__.py,sha256=I1pfz5tLOXV3LQfd9-Wfmuky26XO8o0ZOJXQ6lS1Ohw,65
|
|
39
|
+
python_doctor/scoring/engine.py,sha256=XBlezBowojgywQazjHawGl_QSIhMvL06Y4RNv9FAdxY,11708
|
|
40
|
+
python_doctor/skills/SKILL.md,sha256=E82Sx67gXjYNaAdwxCH_YR4gcUH7kR2hQxa15izOiUM,10354
|
|
41
|
+
python_doctor/skills/__init__.py,sha256=9jNK2waGK3m3sPSIxMwBuirFjd3CB87I9Vj3JgcXfG4,52
|
|
42
|
+
python_doctor/skills/agents.py,sha256=pa664sFEidmgfywoMgHrshPzCOFf8pn4bsKvYI79tRA,3336
|
|
43
|
+
python_doctor/skills/installer.py,sha256=lsunMZVLi0NakSDrGqA_rijnnbq-pvGMUo8K3EKl7T0,8543
|
|
44
|
+
python_doctor/skills/rule_db.py,sha256=rmEPdZxeJKxkaB-zg7JCrhOwIBa2KytXoJN0L5ivdjs,30135
|
|
45
|
+
pycode_doctor-0.1.0.dist-info/METADATA,sha256=gYQRiuGWzjRpQa2nWY4k-ft-mXYbKqOtsEk_fckFB5s,5849
|
|
46
|
+
pycode_doctor-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
47
|
+
pycode_doctor-0.1.0.dist-info/entry_points.txt,sha256=k00e5HBu9PXhbdm2uwFCjQ8VzyROfrlhQDxPAMXcL18,767
|
|
48
|
+
pycode_doctor-0.1.0.dist-info/licenses/LICENSE,sha256=THxgl_tZ7hmDxzXmNERdQldpIlreAZGjnOYuc2_SsjQ,1074
|
|
49
|
+
pycode_doctor-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
python-doctor = python_doctor.cli:main
|
|
3
|
+
|
|
4
|
+
[python_doctor.analyzers]
|
|
5
|
+
bandit = python_doctor.analyzers.bandit_scanner:BanditAnalyzer
|
|
6
|
+
basedpyright = python_doctor.analyzers.basedpyright_analyzer:BasedPyrightAnalyzer
|
|
7
|
+
dependency-vulns = python_doctor.analyzers.dependency_vulns:DependencyVulnerabilityAnalyzer
|
|
8
|
+
deptry = python_doctor.analyzers.deptry_analyzer:DeptryAnalyzer
|
|
9
|
+
detect-secrets = python_doctor.analyzers.detect_secrets_analyzer:DetectSecretsAnalyzer
|
|
10
|
+
mypy = python_doctor.analyzers.mypy_checker:MypyAnalyzer
|
|
11
|
+
radon = python_doctor.analyzers.radon_analyzer:RadonAnalyzer
|
|
12
|
+
ruff = python_doctor.analyzers.ruff:RuffAnalyzer
|
|
13
|
+
typos = python_doctor.analyzers.typos_analyzer:TyposAnalyzer
|
|
14
|
+
vulture = python_doctor.analyzers.vulture_analyzer:VultureAnalyzer
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nabeel S. Qureshi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Structured analysis request passed to analyzers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from python_doctor.config import DoctorConfig
|
|
9
|
+
from python_doctor.models import Category
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class AnalysisRequest:
|
|
14
|
+
"""Input contract shared by all analyzers."""
|
|
15
|
+
|
|
16
|
+
project_root: Path
|
|
17
|
+
files: list[Path]
|
|
18
|
+
config: DoctorConfig
|
|
19
|
+
categories: set[Category]
|
|
20
|
+
profile: str
|
|
21
|
+
framework: str | None = None
|
|
22
|
+
diff_base: str | None = None
|
|
23
|
+
quiet: bool = False
|
|
24
|
+
no_cache: bool = False
|
|
25
|
+
metadata: dict[str, object] = field(default_factory=dict)
|
|
26
|
+
|
|
27
|
+
def config_dict(self) -> dict[str, object]:
|
|
28
|
+
"""Return a mutable dict representation for legacy integrations."""
|
|
29
|
+
data = self.config.__dict__.copy()
|
|
30
|
+
data["framework"] = self.framework
|
|
31
|
+
data["profile"] = self.profile
|
|
32
|
+
data["categories"] = [
|
|
33
|
+
category.value
|
|
34
|
+
for category in sorted(self.categories, key=lambda c: c.value)
|
|
35
|
+
]
|
|
36
|
+
data.update(self.metadata)
|
|
37
|
+
return data
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Analyzer metadata and category mapping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
from python_doctor.models import Category
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class AnalyzerInfo:
|
|
12
|
+
"""Static metadata about a known analyzer."""
|
|
13
|
+
|
|
14
|
+
name: str
|
|
15
|
+
categories: frozenset[Category]
|
|
16
|
+
default_enabled: bool = True
|
|
17
|
+
optional: bool = False
|
|
18
|
+
requires_network: bool = False
|
|
19
|
+
project_wide: bool = False
|
|
20
|
+
profiles: frozenset[str] = field(
|
|
21
|
+
default_factory=lambda: frozenset({"quick", "default", "full"})
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
ANALYZER_CATALOG: dict[str, AnalyzerInfo] = {
|
|
26
|
+
"ruff": AnalyzerInfo(
|
|
27
|
+
name="ruff",
|
|
28
|
+
categories=frozenset(
|
|
29
|
+
{
|
|
30
|
+
Category.QUALITY,
|
|
31
|
+
Category.SECURITY,
|
|
32
|
+
Category.COMPLEXITY,
|
|
33
|
+
Category.DEAD_CODE,
|
|
34
|
+
}
|
|
35
|
+
),
|
|
36
|
+
profiles=frozenset({"quick", "default", "full"}),
|
|
37
|
+
),
|
|
38
|
+
"mypy": AnalyzerInfo(
|
|
39
|
+
name="mypy",
|
|
40
|
+
categories=frozenset({Category.TYPE_SAFETY}),
|
|
41
|
+
profiles=frozenset({"default", "full"}),
|
|
42
|
+
project_wide=True,
|
|
43
|
+
),
|
|
44
|
+
"bandit": AnalyzerInfo(
|
|
45
|
+
name="bandit",
|
|
46
|
+
categories=frozenset({Category.SECURITY}),
|
|
47
|
+
profiles=frozenset({"default", "full"}),
|
|
48
|
+
),
|
|
49
|
+
"radon": AnalyzerInfo(
|
|
50
|
+
name="radon",
|
|
51
|
+
categories=frozenset({Category.COMPLEXITY}),
|
|
52
|
+
profiles=frozenset({"default", "full"}),
|
|
53
|
+
),
|
|
54
|
+
"vulture": AnalyzerInfo(
|
|
55
|
+
name="vulture",
|
|
56
|
+
categories=frozenset({Category.DEAD_CODE}),
|
|
57
|
+
profiles=frozenset({"default", "full"}),
|
|
58
|
+
project_wide=True,
|
|
59
|
+
),
|
|
60
|
+
"deptry": AnalyzerInfo(
|
|
61
|
+
name="deptry",
|
|
62
|
+
categories=frozenset({Category.DEPENDENCIES}),
|
|
63
|
+
profiles=frozenset({"quick", "default", "full"}),
|
|
64
|
+
project_wide=True,
|
|
65
|
+
),
|
|
66
|
+
"dependency-vulns": AnalyzerInfo(
|
|
67
|
+
name="dependency-vulns",
|
|
68
|
+
categories=frozenset({Category.DEPENDENCIES}),
|
|
69
|
+
default_enabled=False,
|
|
70
|
+
optional=True,
|
|
71
|
+
requires_network=True,
|
|
72
|
+
project_wide=True,
|
|
73
|
+
profiles=frozenset({"full"}),
|
|
74
|
+
),
|
|
75
|
+
"detect-secrets": AnalyzerInfo(
|
|
76
|
+
name="detect-secrets",
|
|
77
|
+
categories=frozenset({Category.SECURITY}),
|
|
78
|
+
default_enabled=False,
|
|
79
|
+
optional=True,
|
|
80
|
+
profiles=frozenset({"full"}),
|
|
81
|
+
),
|
|
82
|
+
"basedpyright": AnalyzerInfo(
|
|
83
|
+
name="basedpyright",
|
|
84
|
+
categories=frozenset({Category.TYPE_SAFETY}),
|
|
85
|
+
default_enabled=False,
|
|
86
|
+
optional=True,
|
|
87
|
+
project_wide=True,
|
|
88
|
+
profiles=frozenset({"full"}),
|
|
89
|
+
),
|
|
90
|
+
"typos": AnalyzerInfo(
|
|
91
|
+
name="typos",
|
|
92
|
+
categories=frozenset({Category.QUALITY}),
|
|
93
|
+
default_enabled=False,
|
|
94
|
+
optional=True,
|
|
95
|
+
profiles=frozenset({"full"}),
|
|
96
|
+
),
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_analyzer_info(name: str) -> AnalyzerInfo | None:
|
|
101
|
+
"""Return catalog metadata for an analyzer name."""
|
|
102
|
+
return ANALYZER_CATALOG.get(name)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Analyzer protocol -- the interface every analyzer must implement."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Protocol, runtime_checkable
|
|
6
|
+
|
|
7
|
+
from python_doctor.analysis_request import AnalysisRequest
|
|
8
|
+
from python_doctor.models import Category, Diagnostic
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@runtime_checkable
|
|
12
|
+
class Analyzer(Protocol):
|
|
13
|
+
"""Protocol that all analyzers must satisfy.
|
|
14
|
+
|
|
15
|
+
Analyzers can be built-in or loaded via entry points.
|
|
16
|
+
Each analyzer:
|
|
17
|
+
- Has a unique name and primary category
|
|
18
|
+
- Can check if its underlying tool is available
|
|
19
|
+
- Runs analysis and returns a list of Diagnostics
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def name(self) -> str:
|
|
24
|
+
"""Unique identifier, e.g. 'ruff', 'mypy', 'bandit'."""
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def category(self) -> Category:
|
|
29
|
+
"""Primary category this analyzer contributes to."""
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
async def is_available(self) -> bool:
|
|
33
|
+
"""Check if the underlying tool is installed and runnable.
|
|
34
|
+
|
|
35
|
+
Returns True if the tool is available, False otherwise.
|
|
36
|
+
This should be fast (check PATH, try import, etc).
|
|
37
|
+
"""
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
async def analyze(
|
|
41
|
+
self,
|
|
42
|
+
request: AnalysisRequest,
|
|
43
|
+
) -> list[Diagnostic]:
|
|
44
|
+
"""Run analysis on the given files.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
request: Structured request describing project context, enabled
|
|
48
|
+
categories, profile, files, and configuration.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
List of diagnostics found. Empty list means no issues.
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
TimeoutError: If analysis exceeds configured timeout.
|
|
55
|
+
"""
|
|
56
|
+
...
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Bandit security scanner integration.
|
|
2
|
+
|
|
3
|
+
Bandit is invoked as a subprocess with -f json.
|
|
4
|
+
Results are deduplicated against Ruff's S-prefix findings in the dedup engine.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
import shutil
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from python_doctor.analysis_request import AnalysisRequest
|
|
16
|
+
from python_doctor.models import Category, Diagnostic, Severity
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger("python_doctor")
|
|
19
|
+
|
|
20
|
+
# Bandit severity -> python-doctor Severity
|
|
21
|
+
BANDIT_SEVERITY_MAP: dict[str, Severity] = {
|
|
22
|
+
"HIGH": Severity.ERROR,
|
|
23
|
+
"MEDIUM": Severity.WARNING,
|
|
24
|
+
"LOW": Severity.INFO,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BanditAnalyzer:
|
|
29
|
+
"""Security scanning via Bandit."""
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def name(self) -> str:
|
|
33
|
+
return "bandit"
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def category(self) -> Category:
|
|
37
|
+
return Category.SECURITY
|
|
38
|
+
|
|
39
|
+
async def is_available(self) -> bool:
|
|
40
|
+
"""Check if bandit is on PATH."""
|
|
41
|
+
return shutil.which("bandit") is not None
|
|
42
|
+
|
|
43
|
+
async def analyze(
|
|
44
|
+
self,
|
|
45
|
+
request: AnalysisRequest,
|
|
46
|
+
) -> list[Diagnostic]:
|
|
47
|
+
"""Run bandit with JSON output and parse results."""
|
|
48
|
+
files = request.files
|
|
49
|
+
config = request.config_dict()
|
|
50
|
+
if not files:
|
|
51
|
+
return []
|
|
52
|
+
|
|
53
|
+
cmd = ["bandit", "-f", "json", "--quiet"]
|
|
54
|
+
|
|
55
|
+
str_paths = [str(f) for f in files]
|
|
56
|
+
cmd.extend(str_paths)
|
|
57
|
+
|
|
58
|
+
timeout: int = 60
|
|
59
|
+
if "timeout" in config and isinstance(config["timeout"], (int, float)):
|
|
60
|
+
timeout = int(config["timeout"])
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
proc = await asyncio.create_subprocess_exec(
|
|
64
|
+
*cmd,
|
|
65
|
+
stdout=asyncio.subprocess.PIPE,
|
|
66
|
+
stderr=asyncio.subprocess.PIPE,
|
|
67
|
+
)
|
|
68
|
+
stdout, stderr = await asyncio.wait_for(
|
|
69
|
+
proc.communicate(),
|
|
70
|
+
timeout=timeout,
|
|
71
|
+
)
|
|
72
|
+
except asyncio.TimeoutError:
|
|
73
|
+
logger.warning("Bandit timed out")
|
|
74
|
+
return []
|
|
75
|
+
except FileNotFoundError:
|
|
76
|
+
logger.warning("Bandit binary not found")
|
|
77
|
+
return []
|
|
78
|
+
|
|
79
|
+
# Exit codes: 0 = clean, 1 = issues found, 2 = error
|
|
80
|
+
if proc.returncode == 2:
|
|
81
|
+
logger.error("Bandit error: %s", stderr.decode())
|
|
82
|
+
return []
|
|
83
|
+
|
|
84
|
+
output = stdout.decode()
|
|
85
|
+
if not output.strip():
|
|
86
|
+
return []
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
data = json.loads(output)
|
|
90
|
+
except json.JSONDecodeError:
|
|
91
|
+
logger.error("Failed to parse Bandit JSON output")
|
|
92
|
+
return []
|
|
93
|
+
|
|
94
|
+
results = data.get("results", [])
|
|
95
|
+
if not isinstance(results, list):
|
|
96
|
+
return []
|
|
97
|
+
return [_map_bandit_result(r) for r in results]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _safe_int(val: object, default: int = 0) -> int:
|
|
101
|
+
"""Safely convert a value from JSON to int."""
|
|
102
|
+
if val is None:
|
|
103
|
+
return default
|
|
104
|
+
if isinstance(val, int):
|
|
105
|
+
return val
|
|
106
|
+
try:
|
|
107
|
+
return int(str(val))
|
|
108
|
+
except (TypeError, ValueError):
|
|
109
|
+
return default
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _map_bandit_result(raw: dict[str, object]) -> Diagnostic:
|
|
113
|
+
"""Map a single Bandit JSON result to our Diagnostic model."""
|
|
114
|
+
severity = BANDIT_SEVERITY_MAP.get(
|
|
115
|
+
str(raw.get("issue_severity", "LOW")),
|
|
116
|
+
Severity.INFO,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
test_id = str(raw.get("test_id", "B000"))
|
|
120
|
+
|
|
121
|
+
# Build fix suggestion from CWE
|
|
122
|
+
cwe = raw.get("issue_cwe")
|
|
123
|
+
fix_text: str | None = None
|
|
124
|
+
if isinstance(cwe, dict) and cwe.get("id"):
|
|
125
|
+
fix_text = f"CWE-{cwe['id']}"
|
|
126
|
+
|
|
127
|
+
help_url = raw.get("more_info")
|
|
128
|
+
|
|
129
|
+
end_col = raw.get("end_col_offset")
|
|
130
|
+
|
|
131
|
+
return Diagnostic(
|
|
132
|
+
file_path=Path(str(raw.get("filename", "unknown"))),
|
|
133
|
+
line=_safe_int(raw.get("line_number")),
|
|
134
|
+
column=_safe_int(raw.get("col_offset")),
|
|
135
|
+
severity=severity,
|
|
136
|
+
rule_id=test_id,
|
|
137
|
+
tool="bandit",
|
|
138
|
+
category=Category.SECURITY,
|
|
139
|
+
message=str(raw.get("issue_text", "")),
|
|
140
|
+
fix=fix_text,
|
|
141
|
+
help_url=str(help_url) if help_url else None,
|
|
142
|
+
end_column=_safe_int(end_col) if end_col else None,
|
|
143
|
+
)
|