codaviz 0.5.0__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.
codaviz-0.5.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
codaviz-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: codaviz
3
+ Version: 0.5.0
4
+ Summary: Analyze and visualize complexity hotspots in Python codebases.
5
+ Author: Stefane Fermigier
6
+ Author-email: Stefane Fermigier <sf@abilian.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Dist: cognitive-complexity>=1.3
10
+ Requires-Dist: cyclopts>=3.0
11
+ Requires-Dist: jinja2>=3.1
12
+ Requires-Dist: mccabe>=0.7
13
+ Requires-Dist: radon>=6.0
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+
17
+ # codaviz
18
+
19
+ A lightweight CLI that analyzes complexity in Python codebases and emits a single, self-contained, interactive HTML report — a simpler, local alternative to SonarQube for spotting where to refactor.
20
+
21
+ Point it at a repo and it ranks **complexity hotspots**, draws a **treemap** (sized by lines of code, colored by a metric you pick), lets you **drill into any module** to read its functions and source, and flags **circular imports** and **over-threshold functions**. No server, no database, no network — the report is one HTML file you can open offline or email to a teammate.
22
+
23
+ ![codaviz interactive report — treemap, top-modules chart, and per-function drill-down with cyclomatic + cognitive complexity](docs/images/screenshot.png)
24
+
25
+ ## Quick start
26
+
27
+ codaviz is a [uv](https://docs.astral.sh/uv/) project. From a checkout:
28
+
29
+ ```bash
30
+ uv sync # install
31
+ uv run codaviz /path/to/project # writes ./report.html
32
+ open report.html # (macOS; use xdg-open on Linux)
33
+ ```
34
+
35
+ Try it on codaviz itself:
36
+
37
+ ```bash
38
+ uv run codaviz . && open report.html
39
+ ```
40
+
41
+ To install it as a standalone command:
42
+
43
+ ```bash
44
+ uv tool install . # then, anywhere: codaviz /path/to/project
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ```
50
+ codaviz [OPTIONS] [PATH]
51
+
52
+ PATH Project directory to analyze (default: current dir)
53
+
54
+ -f, --format html | json | csv (default: html)
55
+ -o, --output FILE Output file
56
+ (html → report.html; json/csv → stdout unless set)
57
+ --no-source Omit embedded source snippets (smaller, shareable report)
58
+ --version Show version and exit
59
+ -h, --help Show help and exit
60
+ ```
61
+
62
+ Examples:
63
+
64
+ ```bash
65
+ codaviz ~/src/myapp # interactive report.html
66
+ codaviz ~/src/myapp -o myapp.html # custom output path
67
+ codaviz ~/src/myapp --no-source -o share.html # no source embedded
68
+ codaviz ~/src/myapp -f json > data.json # raw entity data
69
+ codaviz ~/src/myapp -f csv > data.csv # one row per package/module/function
70
+ ```
71
+
72
+ ## The report
73
+
74
+ - **Treemap** — every module is a tile sized by lines of code and colored by the selected metric (greener = better, redder = worse). Click a package to zoom in.
75
+ - **Metric selector** — switch between **Maintainability index** (default), **max/total cyclomatic**, **max/total cognitive**, and **lines of code**; the treemap, bar chart, and table all re-rank instantly.
76
+ - **Hotspots table** — every module sorted by the selected metric, with LOC / MI / max & total cyclomatic / max & total cognitive / function count.
77
+ - **Function detail** — click a tile, bar, or row to see that module's functions, each with a **CC** (cyclomatic) and **Cog** (cognitive) badge, line number, and source snippet. Functions over either threshold get a "consider extracting" / "hard to follow" hint.
78
+ - **Circular imports** — modules that import each other (statically detected) are listed as cycles.
79
+
80
+ ## What gets analyzed
81
+
82
+ Inside a git repo, codaviz analyzes the Python files git knows about — tracked **and** uncommitted — while honoring `.gitignore` (so `.venv`, build output, and ignored trees are skipped). Outside a repo, it walks the directory. On top of that it always skips common noise: virtualenvs, caches, `build/`, `dist/`, `node_modules/`, `site-packages/`, `migrations/`, and test files (`tests/`, `test_*.py`, `*_test.py`, `conftest.py`) unless you opt in.
83
+
84
+ ## Metrics
85
+
86
+ | Metric | Meaning | Direction |
87
+ |---|---|---|
88
+ | **Cyclomatic (CC)** | McCabe complexity — branch/loop count + 1. Per function. Matches Ruff's C901 / `python -m mccabe`. | higher = worse |
89
+ | **Cognitive (Cog)** | SonarSource cognitive complexity — penalises *nesting*, ignores shorthand humans read easily. The better "how hard to understand" signal. Per function. | higher = worse |
90
+ | **Maintainability index (MI)** | radon's 0–100 composite (≥20 = A/good, 10–19 = B, <10 = C). Per module. Kept as the familiar number. | lower = worse |
91
+ | **SLOC** | Source lines of code (excludes blanks/comments). | — (used for tile size) |
92
+
93
+ Cyclomatic complexity comes from [`mccabe`](https://github.com/PyCQA/mccabe) (so the numbers match Ruff), cognitive from [`cognitive_complexity`](https://github.com/Melevir/cognitive_complexity), MI + SLOC from [`radon`](https://radon.readthedocs.io/), and circular imports from a static `ast` import graph (no code is executed).
94
+
95
+ ## Configuration
96
+
97
+ Optional `[tool.codaviz]` table in the analyzed project's `pyproject.toml`:
98
+
99
+ ```toml
100
+ [tool.codaviz]
101
+ exclude = ["generated/*.py", "vendor/**"] # extra glob patterns to skip
102
+ max-complexity = 15 # cyclomatic threshold for hints
103
+ max-cognitive = 15 # cognitive threshold for hints
104
+ include-tests = false # set true to analyze test files too
105
+ ```
106
+
107
+ ## Known limitations
108
+
109
+ - **Nested defs**: closures and methods of function-local classes are folded into their enclosing function's score rather than listed separately — matching how Ruff/mccabe report the outer function.
110
+ - **Circular imports**: resolution favors false negatives over false positives — unusual layouts (some `src/` setups, namespace packages) may under-report. Relative imports always resolve correctly.
111
+ - **Color scale**: the badness ramp is green→amber→red with a "better → worse" legend and a numeric table as non-color channels; a fully colorblind-safe palette is a planned option.
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ make test # uv run pytest
117
+ make lint # ruff check + format check + type checks
118
+ make format # ruff format + autofix
119
+ ```
120
+
121
+ The test suite spans unit / integration / end-to-end tiers, including in-browser execution of the report's JavaScript via Node.
122
+
123
+ ## Status
124
+
125
+ **0.5.0 — first public release.** Stable and usable: hotspots, treemap, drill-down, cyclomatic + cognitive complexity, maintainability index, circular imports, threshold hints, and HTML/JSON/CSV output. Planned next (in rough order): **churn-weighted hotspots** (complexity × git change-frequency), **coupling metrics** (afferent/efferent, instability), and **trends over time**. See [`notes/`](notes/) for the vision, spec, and implementation plan, and [`CHANGES.md`](CHANGES.md) for the changelog.
126
+
127
+ ## Non-goals
128
+
129
+ Security scanning (use Bandit), runtime profiling (use `cProfile`/`scalene`), and test coverage (use `pytest-cov`) are out of scope — codaviz focuses on structural complexity.
130
+
131
+ ## License
132
+
133
+ Apache License 2.0 — see [`LICENSE`](LICENSE).
@@ -0,0 +1,117 @@
1
+ # codaviz
2
+
3
+ A lightweight CLI that analyzes complexity in Python codebases and emits a single, self-contained, interactive HTML report — a simpler, local alternative to SonarQube for spotting where to refactor.
4
+
5
+ Point it at a repo and it ranks **complexity hotspots**, draws a **treemap** (sized by lines of code, colored by a metric you pick), lets you **drill into any module** to read its functions and source, and flags **circular imports** and **over-threshold functions**. No server, no database, no network — the report is one HTML file you can open offline or email to a teammate.
6
+
7
+ ![codaviz interactive report — treemap, top-modules chart, and per-function drill-down with cyclomatic + cognitive complexity](docs/images/screenshot.png)
8
+
9
+ ## Quick start
10
+
11
+ codaviz is a [uv](https://docs.astral.sh/uv/) project. From a checkout:
12
+
13
+ ```bash
14
+ uv sync # install
15
+ uv run codaviz /path/to/project # writes ./report.html
16
+ open report.html # (macOS; use xdg-open on Linux)
17
+ ```
18
+
19
+ Try it on codaviz itself:
20
+
21
+ ```bash
22
+ uv run codaviz . && open report.html
23
+ ```
24
+
25
+ To install it as a standalone command:
26
+
27
+ ```bash
28
+ uv tool install . # then, anywhere: codaviz /path/to/project
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```
34
+ codaviz [OPTIONS] [PATH]
35
+
36
+ PATH Project directory to analyze (default: current dir)
37
+
38
+ -f, --format html | json | csv (default: html)
39
+ -o, --output FILE Output file
40
+ (html → report.html; json/csv → stdout unless set)
41
+ --no-source Omit embedded source snippets (smaller, shareable report)
42
+ --version Show version and exit
43
+ -h, --help Show help and exit
44
+ ```
45
+
46
+ Examples:
47
+
48
+ ```bash
49
+ codaviz ~/src/myapp # interactive report.html
50
+ codaviz ~/src/myapp -o myapp.html # custom output path
51
+ codaviz ~/src/myapp --no-source -o share.html # no source embedded
52
+ codaviz ~/src/myapp -f json > data.json # raw entity data
53
+ codaviz ~/src/myapp -f csv > data.csv # one row per package/module/function
54
+ ```
55
+
56
+ ## The report
57
+
58
+ - **Treemap** — every module is a tile sized by lines of code and colored by the selected metric (greener = better, redder = worse). Click a package to zoom in.
59
+ - **Metric selector** — switch between **Maintainability index** (default), **max/total cyclomatic**, **max/total cognitive**, and **lines of code**; the treemap, bar chart, and table all re-rank instantly.
60
+ - **Hotspots table** — every module sorted by the selected metric, with LOC / MI / max & total cyclomatic / max & total cognitive / function count.
61
+ - **Function detail** — click a tile, bar, or row to see that module's functions, each with a **CC** (cyclomatic) and **Cog** (cognitive) badge, line number, and source snippet. Functions over either threshold get a "consider extracting" / "hard to follow" hint.
62
+ - **Circular imports** — modules that import each other (statically detected) are listed as cycles.
63
+
64
+ ## What gets analyzed
65
+
66
+ Inside a git repo, codaviz analyzes the Python files git knows about — tracked **and** uncommitted — while honoring `.gitignore` (so `.venv`, build output, and ignored trees are skipped). Outside a repo, it walks the directory. On top of that it always skips common noise: virtualenvs, caches, `build/`, `dist/`, `node_modules/`, `site-packages/`, `migrations/`, and test files (`tests/`, `test_*.py`, `*_test.py`, `conftest.py`) unless you opt in.
67
+
68
+ ## Metrics
69
+
70
+ | Metric | Meaning | Direction |
71
+ |---|---|---|
72
+ | **Cyclomatic (CC)** | McCabe complexity — branch/loop count + 1. Per function. Matches Ruff's C901 / `python -m mccabe`. | higher = worse |
73
+ | **Cognitive (Cog)** | SonarSource cognitive complexity — penalises *nesting*, ignores shorthand humans read easily. The better "how hard to understand" signal. Per function. | higher = worse |
74
+ | **Maintainability index (MI)** | radon's 0–100 composite (≥20 = A/good, 10–19 = B, <10 = C). Per module. Kept as the familiar number. | lower = worse |
75
+ | **SLOC** | Source lines of code (excludes blanks/comments). | — (used for tile size) |
76
+
77
+ Cyclomatic complexity comes from [`mccabe`](https://github.com/PyCQA/mccabe) (so the numbers match Ruff), cognitive from [`cognitive_complexity`](https://github.com/Melevir/cognitive_complexity), MI + SLOC from [`radon`](https://radon.readthedocs.io/), and circular imports from a static `ast` import graph (no code is executed).
78
+
79
+ ## Configuration
80
+
81
+ Optional `[tool.codaviz]` table in the analyzed project's `pyproject.toml`:
82
+
83
+ ```toml
84
+ [tool.codaviz]
85
+ exclude = ["generated/*.py", "vendor/**"] # extra glob patterns to skip
86
+ max-complexity = 15 # cyclomatic threshold for hints
87
+ max-cognitive = 15 # cognitive threshold for hints
88
+ include-tests = false # set true to analyze test files too
89
+ ```
90
+
91
+ ## Known limitations
92
+
93
+ - **Nested defs**: closures and methods of function-local classes are folded into their enclosing function's score rather than listed separately — matching how Ruff/mccabe report the outer function.
94
+ - **Circular imports**: resolution favors false negatives over false positives — unusual layouts (some `src/` setups, namespace packages) may under-report. Relative imports always resolve correctly.
95
+ - **Color scale**: the badness ramp is green→amber→red with a "better → worse" legend and a numeric table as non-color channels; a fully colorblind-safe palette is a planned option.
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ make test # uv run pytest
101
+ make lint # ruff check + format check + type checks
102
+ make format # ruff format + autofix
103
+ ```
104
+
105
+ The test suite spans unit / integration / end-to-end tiers, including in-browser execution of the report's JavaScript via Node.
106
+
107
+ ## Status
108
+
109
+ **0.5.0 — first public release.** Stable and usable: hotspots, treemap, drill-down, cyclomatic + cognitive complexity, maintainability index, circular imports, threshold hints, and HTML/JSON/CSV output. Planned next (in rough order): **churn-weighted hotspots** (complexity × git change-frequency), **coupling metrics** (afferent/efferent, instability), and **trends over time**. See [`notes/`](notes/) for the vision, spec, and implementation plan, and [`CHANGES.md`](CHANGES.md) for the changelog.
110
+
111
+ ## Non-goals
112
+
113
+ Security scanning (use Bandit), runtime profiling (use `cProfile`/`scalene`), and test coverage (use `pytest-cov`) are out of scope — codaviz focuses on structural complexity.
114
+
115
+ ## License
116
+
117
+ Apache License 2.0 — see [`LICENSE`](LICENSE).
@@ -0,0 +1,58 @@
1
+ [project]
2
+ name = "codaviz"
3
+ version = "0.5.0"
4
+ description = "Analyze and visualize complexity hotspots in Python codebases."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Stefane Fermigier", email = "sf@abilian.com" }
10
+ ]
11
+ requires-python = ">=3.12"
12
+ dependencies = [
13
+ "cognitive-complexity>=1.3",
14
+ "cyclopts>=3.0",
15
+ "jinja2>=3.1",
16
+ "mccabe>=0.7",
17
+ "radon>=6.0",
18
+ ]
19
+
20
+ [project.scripts]
21
+ codaviz = "codaviz.cli:main"
22
+
23
+ [build-system]
24
+ requires = ["uv_build>=0.11.16,<0.12.0"]
25
+ build-backend = "uv_build"
26
+
27
+ [dependency-groups]
28
+ dev = [
29
+ "mypy>=2.1.0",
30
+ "nox>=2026.4.10",
31
+ "pre-commit>=4.6.0",
32
+ "pyrefly>=1.0.0",
33
+ "pytest>=9.0.3",
34
+ "pytest-cov>=7.1.0",
35
+ "ruff>=0.15.16",
36
+ "ty>=0.0.47",
37
+ ]
38
+
39
+ [tool.pytest.ini_options]
40
+ markers = [
41
+ "unit: fast, isolated unit tests (no I/O)",
42
+ "integration: component-interaction tests (file I/O)",
43
+ "e2e: full CLI workflow tests",
44
+ ]
45
+
46
+ [tool.codaviz]
47
+ # Extra glob patterns to exclude from analysis (in addition to smart defaults).
48
+ exclude = []
49
+ # Cyclomatic-complexity threshold above which a function is flagged.
50
+ max-complexity = 15
51
+ # Cognitive-complexity threshold above which a function is flagged.
52
+ max-cognitive = 15
53
+
54
+ [tool.mypy]
55
+ # These ship no type stubs / py.typed marker.
56
+ [[tool.mypy.overrides]]
57
+ module = ["radon.*", "mccabe", "cognitive_complexity.*"]
58
+ ignore_missing_imports = true
@@ -0,0 +1,7 @@
1
+ """codaviz — analyze and visualize complexity hotspots in Python codebases."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from codaviz._version import __version__
6
+
7
+ __all__ = ["__version__"]
@@ -0,0 +1,10 @@
1
+ """Resolve the installed package version (single source of truth: pyproject)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.metadata import PackageNotFoundError, version
6
+
7
+ try:
8
+ __version__ = version("codaviz")
9
+ except PackageNotFoundError: # running from a source tree without an install
10
+ __version__ = "0.0.0"
@@ -0,0 +1,12 @@
1
+ """Analysis orchestration: turn discovered files into a flat entity list.
2
+
3
+ Builds PACKAGE, MODULE (SLOC + maintainability index), and FUNCTION (cyclomatic
4
+ complexity) entities. Circular-import findings are computed separately by
5
+ ``analysis.imports`` (static AST, surfaced in the HTML report).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from codaviz.analysis.project import analyze_project
11
+
12
+ __all__ = ["analyze_project"]
@@ -0,0 +1,63 @@
1
+ """Per-function complexity: cyclomatic (mccabe) + cognitive (SonarSource).
2
+
3
+ Cyclomatic complexity comes from the ``mccabe`` library, so the numbers match
4
+ Ruff's C901 and ``python -m mccabe``. Cognitive complexity comes from the
5
+ ``cognitive_complexity`` library. End lines (for source snippets) come from the
6
+ AST, joined to mccabe's per-function results by line number.
7
+
8
+ Like Ruff/mccabe, nested closures and function-local-class methods are folded
9
+ into their enclosing function rather than listed separately.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import ast
15
+ from dataclasses import dataclass
16
+
17
+ from cognitive_complexity.api import get_cognitive_complexity
18
+ from mccabe import PathGraphingAstVisitor
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class FunctionInfo:
23
+ """Complexity for a single function or method."""
24
+
25
+ name: str # qualified name, e.g. "A.method"
26
+ lineno: int
27
+ endline: int
28
+ complexity: int # cyclomatic (mccabe)
29
+ cognitive: int # cognitive (SonarSource)
30
+
31
+
32
+ def function_infos(source: str) -> list[FunctionInfo]:
33
+ """Return complexity records for the functions/methods in ``source``.
34
+
35
+ Raises ``SyntaxError`` if ``source`` is not valid Python.
36
+ """
37
+ tree = ast.parse(source)
38
+
39
+ visitor = PathGraphingAstVisitor()
40
+ visitor.preorder(tree, visitor)
41
+ cyclomatic = {g.lineno: (g.entity, g.complexity()) for g in visitor.graphs.values()}
42
+
43
+ nodes: dict[int, ast.FunctionDef | ast.AsyncFunctionDef] = {
44
+ node.lineno: node
45
+ for node in ast.walk(tree)
46
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
47
+ }
48
+
49
+ infos = []
50
+ for lineno, (name, complexity) in sorted(cyclomatic.items()):
51
+ node = nodes.get(lineno)
52
+ if node is None:
53
+ continue
54
+ infos.append(
55
+ FunctionInfo(
56
+ name=name,
57
+ lineno=lineno,
58
+ endline=node.end_lineno or lineno,
59
+ complexity=complexity,
60
+ cognitive=get_cognitive_complexity(node),
61
+ ),
62
+ )
63
+ return infos