complexipy 8.1.0__tar.gz → 8.2.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.
- {complexipy-8.1.0 → complexipy-8.2.0}/Cargo.lock +28 -6
- {complexipy-8.1.0 → complexipy-8.2.0}/Cargo.toml +1 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/PKG-INFO +5 -5
- {complexipy-8.1.0 → complexipy-8.2.0}/README.md +4 -4
- {complexipy-8.1.0 → complexipy-8.2.0}/complexipy/__init__.py +6 -3
- {complexipy-8.1.0 → complexipy-8.2.0}/complexipy/_complexipy.pyi +53 -17
- {complexipy-8.1.0 → complexipy-8.2.0}/complexipy/cli.py +10 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/Cargo.toml +4 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/args/tests.rs +14 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/args.rs +6 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/main.rs +8 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/diff.rs +14 -3
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/fix/tests.rs +13 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/fix.rs +119 -53
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/messages/tests.rs +40 -8
- complexipy-8.2.0/crates/complexipy-cli/src/output/messages.rs +160 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/refactor/tests.rs +45 -4
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/refactor.rs +78 -28
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/render/tests.rs +34 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/render.rs +40 -25
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/rows/tests.rs +27 -6
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/rows.rs +25 -10
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output.rs +33 -3
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/run/tests.rs +251 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/run.rs +124 -59
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/types.rs +9 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/cache/tests.rs +112 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/cache.rs +124 -71
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/config/tests.rs +143 -6
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/config.rs +91 -14
- complexipy-8.2.0/crates/complexipy-cli/src/utils/fingerprint.rs +59 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/fix/tests.rs +95 -17
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/fix.rs +54 -27
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/gitlab/tests.rs +54 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/gitlab.rs +34 -34
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/ignored/tests.rs +46 -15
- complexipy-8.2.0/crates/complexipy-cli/src/utils/ignored.rs +66 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/sarif/tests.rs +60 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/sarif.rs +67 -26
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/snapshot/tests.rs +99 -28
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/snapshot.rs +39 -10
- complexipy-8.2.0/crates/complexipy-cli/src/utils/toml.rs +31 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils.rs +1 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/api.rs +2 -0
- complexipy-8.2.0/crates/complexipy-core/src/classes.rs +243 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/cognitive_complexity.rs +273 -136
- complexipy-8.2.0/crates/complexipy-core/src/config.rs +378 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/diff/tests.rs +186 -10
- complexipy-8.2.0/crates/complexipy-core/src/diff.rs +484 -0
- complexipy-8.2.0/crates/complexipy-core/src/encoding/tests.rs +86 -0
- complexipy-8.2.0/crates/complexipy-core/src/encoding.rs +165 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/fix.rs +37 -13
- complexipy-8.2.0/crates/complexipy-core/src/fs_guard/tests.rs +177 -0
- complexipy-8.2.0/crates/complexipy-core/src/fs_guard.rs +178 -0
- complexipy-8.2.0/crates/complexipy-core/src/helpers/exclude/tests.rs +439 -0
- complexipy-8.2.0/crates/complexipy-core/src/helpers/exclude.rs +379 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/lib.rs +5 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/refactor_plans.rs +6 -19
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/complexity/tests.rs +140 -38
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/complexity.rs +266 -379
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/registry/tests.rs +145 -7
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/registry.rs +105 -50
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/types.rs +11 -1
- complexipy-8.2.0/crates/complexipy-core/src/runner.rs +645 -0
- complexipy-8.2.0/crates/complexipy-core/src/sanitize/tests.rs +38 -0
- complexipy-8.2.0/crates/complexipy-core/src/sanitize.rs +44 -0
- complexipy-8.2.0/crates/complexipy-core/src/syntax_tree/tests.rs +92 -0
- complexipy-8.2.0/crates/complexipy-core/src/syntax_tree.rs +225 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/utils/export_tests.rs +18 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/utils/tests.rs +7 -3
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/utils.rs +240 -123
- complexipy-8.2.0/crates/complexipy-core/tests/it/config.rs +368 -0
- complexipy-8.2.0/crates/complexipy-core/tests/it/deep_expressions.rs +95 -0
- complexipy-8.2.0/crates/complexipy-core/tests/it/discovery.rs +93 -0
- complexipy-8.2.0/crates/complexipy-core/tests/it/gate_coverage.rs +138 -0
- complexipy-8.2.0/crates/complexipy-core/tests/it/line_endings.rs +118 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/main.rs +4 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/Cargo.toml +3 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/src/analysis.rs +206 -44
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/src/documents.rs +47 -5
- complexipy-8.2.0/crates/complexipy-lsp/src/lib.rs +30 -0
- complexipy-8.2.0/crates/complexipy-lsp/src/main.rs +11 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/src/server/tests.rs +221 -28
- complexipy-8.2.0/crates/complexipy-lsp/src/server.rs +1112 -0
- complexipy-8.2.0/crates/complexipy-lsp/src/transport/tests.rs +146 -0
- complexipy-8.2.0/crates/complexipy-lsp/src/transport.rs +214 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/src/workspace/tests.rs +65 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/src/workspace.rs +52 -15
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/tests/it/analysis.rs +190 -11
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/tests/it/documents.rs +24 -1
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/tests/it/protocol.rs +125 -13
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-python/Cargo.toml +4 -0
- complexipy-8.2.0/crates/complexipy-python/src/lib.rs +341 -0
- complexipy-8.1.0/crates/complexipy-cli/src/output/messages.rs +0 -70
- complexipy-8.1.0/crates/complexipy-cli/src/utils/ignored.rs +0 -88
- complexipy-8.1.0/crates/complexipy-cli/src/utils/toml.rs +0 -19
- complexipy-8.1.0/crates/complexipy-core/src/classes.rs +0 -124
- complexipy-8.1.0/crates/complexipy-core/src/config.rs +0 -230
- complexipy-8.1.0/crates/complexipy-core/src/diff.rs +0 -299
- complexipy-8.1.0/crates/complexipy-core/src/helpers/exclude/tests.rs +0 -214
- complexipy-8.1.0/crates/complexipy-core/src/helpers/exclude.rs +0 -141
- complexipy-8.1.0/crates/complexipy-core/src/runner.rs +0 -288
- complexipy-8.1.0/crates/complexipy-core/tests/it/config.rs +0 -228
- complexipy-8.1.0/crates/complexipy-lsp/src/lib.rs +0 -14
- complexipy-8.1.0/crates/complexipy-lsp/src/main.rs +0 -3
- complexipy-8.1.0/crates/complexipy-lsp/src/server.rs +0 -649
- complexipy-8.1.0/crates/complexipy-python/src/lib.rs +0 -233
- {complexipy-8.1.0 → complexipy-8.2.0}/LICENSE +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/complexipy/py.typed +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/lib.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/output/diff/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/types/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/paths/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-cli/src/utils/paths.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/Cargo.toml +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/api/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/fix/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/helpers.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules/types/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/src/rules.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/exclude.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/lib_surface.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/plans_for_function.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/python315.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-core/tests/it/syntax_error.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-lsp/tests/it/main.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-types/Cargo.toml +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-types/src/lib.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-types/src/python/tests.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/crates/complexipy-types/src/python.rs +0 -0
- {complexipy-8.1.0 → complexipy-8.2.0}/pyproject.toml +0 -0
|
@@ -322,13 +322,14 @@ dependencies = [
|
|
|
322
322
|
|
|
323
323
|
[[package]]
|
|
324
324
|
name = "complexipy-cli"
|
|
325
|
-
version = "8.
|
|
325
|
+
version = "8.2.0"
|
|
326
326
|
dependencies = [
|
|
327
327
|
"blake2",
|
|
328
328
|
"clap",
|
|
329
329
|
"comfy-table",
|
|
330
330
|
"complexipy-core",
|
|
331
331
|
"jsonschema",
|
|
332
|
+
"mimalloc",
|
|
332
333
|
"owo-colors",
|
|
333
334
|
"schemars",
|
|
334
335
|
"serde",
|
|
@@ -344,7 +345,7 @@ dependencies = [
|
|
|
344
345
|
|
|
345
346
|
[[package]]
|
|
346
347
|
name = "complexipy-core"
|
|
347
|
-
version = "8.
|
|
348
|
+
version = "8.2.0"
|
|
348
349
|
dependencies = [
|
|
349
350
|
"complexipy-types",
|
|
350
351
|
"csv",
|
|
@@ -365,12 +366,13 @@ dependencies = [
|
|
|
365
366
|
|
|
366
367
|
[[package]]
|
|
367
368
|
name = "complexipy-lsp"
|
|
368
|
-
version = "8.
|
|
369
|
+
version = "8.2.0"
|
|
369
370
|
dependencies = [
|
|
370
371
|
"complexipy-core",
|
|
371
372
|
"crossbeam-channel",
|
|
372
373
|
"lsp-server",
|
|
373
374
|
"lsp-types",
|
|
375
|
+
"mimalloc",
|
|
374
376
|
"serde",
|
|
375
377
|
"serde_json",
|
|
376
378
|
"tempfile",
|
|
@@ -378,19 +380,21 @@ dependencies = [
|
|
|
378
380
|
|
|
379
381
|
[[package]]
|
|
380
382
|
name = "complexipy-python"
|
|
381
|
-
version = "8.
|
|
383
|
+
version = "8.2.0"
|
|
382
384
|
dependencies = [
|
|
383
385
|
"clap",
|
|
384
386
|
"complexipy-cli",
|
|
385
387
|
"complexipy-core",
|
|
386
388
|
"complexipy-lsp",
|
|
387
389
|
"complexipy-types",
|
|
390
|
+
"mimalloc",
|
|
388
391
|
"pyo3",
|
|
392
|
+
"rayon",
|
|
389
393
|
]
|
|
390
394
|
|
|
391
395
|
[[package]]
|
|
392
396
|
name = "complexipy-types"
|
|
393
|
-
version = "8.
|
|
397
|
+
version = "8.2.0"
|
|
394
398
|
dependencies = [
|
|
395
399
|
"pyo3",
|
|
396
400
|
"serde",
|
|
@@ -398,7 +402,7 @@ dependencies = [
|
|
|
398
402
|
|
|
399
403
|
[[package]]
|
|
400
404
|
name = "complexipy-wasm"
|
|
401
|
-
version = "8.
|
|
405
|
+
version = "8.2.0"
|
|
402
406
|
dependencies = [
|
|
403
407
|
"complexipy-core",
|
|
404
408
|
"console_error_panic_hook",
|
|
@@ -1010,6 +1014,15 @@ version = "0.2.184"
|
|
|
1010
1014
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1011
1015
|
checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af"
|
|
1012
1016
|
|
|
1017
|
+
[[package]]
|
|
1018
|
+
name = "libmimalloc-sys"
|
|
1019
|
+
version = "0.1.46"
|
|
1020
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1021
|
+
checksum = "bc89deee4af0429081d2a518c0431ae068222a5a262a3bc6ff4d8535ec2e02fe"
|
|
1022
|
+
dependencies = [
|
|
1023
|
+
"cc",
|
|
1024
|
+
]
|
|
1025
|
+
|
|
1013
1026
|
[[package]]
|
|
1014
1027
|
name = "linked-hash-map"
|
|
1015
1028
|
version = "0.5.6"
|
|
@@ -1104,6 +1117,15 @@ version = "0.3.0"
|
|
|
1104
1117
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1105
1118
|
checksum = "c2a86d3146ed3995b5913c414f6664344b9617457320782e64f0bb44afd49d74"
|
|
1106
1119
|
|
|
1120
|
+
[[package]]
|
|
1121
|
+
name = "mimalloc"
|
|
1122
|
+
version = "0.1.49"
|
|
1123
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1124
|
+
checksum = "aca3c01a711f395b4257b81674c0e90e8dd1f1e62c4b7db45f684cc7a4fcb18a"
|
|
1125
|
+
dependencies = [
|
|
1126
|
+
"libmimalloc-sys",
|
|
1127
|
+
]
|
|
1128
|
+
|
|
1107
1129
|
[[package]]
|
|
1108
1130
|
name = "minimal-lexical"
|
|
1109
1131
|
version = "0.2.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: complexipy
|
|
3
|
-
Version: 8.
|
|
3
|
+
Version: 8.2.0
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Environment :: Console
|
|
6
6
|
Classifier: Intended Audience :: Developers
|
|
@@ -136,11 +136,11 @@ for func in result.functions:
|
|
|
136
136
|
<summary><strong>🔧 GitHub Actions</strong></summary>
|
|
137
137
|
|
|
138
138
|
```yaml
|
|
139
|
-
- uses: rohaquinlop/complexipy-action@
|
|
139
|
+
- uses: rohaquinlop/complexipy-action@v8
|
|
140
140
|
with:
|
|
141
141
|
paths: .
|
|
142
142
|
max_complexity_allowed: 10
|
|
143
|
-
|
|
143
|
+
output_json: true
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
</details>
|
|
@@ -151,7 +151,7 @@ for func in result.functions:
|
|
|
151
151
|
```yaml
|
|
152
152
|
repos:
|
|
153
153
|
- repo: https://github.com/rohaquinlop/complexipy-pre-commit
|
|
154
|
-
rev:
|
|
154
|
+
rev: v8.1.0
|
|
155
155
|
hooks:
|
|
156
156
|
- id: complexipy
|
|
157
157
|
```
|
|
@@ -161,7 +161,7 @@ repos:
|
|
|
161
161
|
<details>
|
|
162
162
|
<summary><strong>🔌 VS Code Extension</strong></summary>
|
|
163
163
|
|
|
164
|
-
Install from the [
|
|
164
|
+
Install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy). It runs the complexipy language server, so install `complexipy` too (`uv tool install complexipy`). Inlay hints, hover, and warnings update as you type.
|
|
165
165
|
|
|
166
166
|
</details>
|
|
167
167
|
|
|
@@ -98,11 +98,11 @@ for func in result.functions:
|
|
|
98
98
|
<summary><strong>🔧 GitHub Actions</strong></summary>
|
|
99
99
|
|
|
100
100
|
```yaml
|
|
101
|
-
- uses: rohaquinlop/complexipy-action@
|
|
101
|
+
- uses: rohaquinlop/complexipy-action@v8
|
|
102
102
|
with:
|
|
103
103
|
paths: .
|
|
104
104
|
max_complexity_allowed: 10
|
|
105
|
-
|
|
105
|
+
output_json: true
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
</details>
|
|
@@ -113,7 +113,7 @@ for func in result.functions:
|
|
|
113
113
|
```yaml
|
|
114
114
|
repos:
|
|
115
115
|
- repo: https://github.com/rohaquinlop/complexipy-pre-commit
|
|
116
|
-
rev:
|
|
116
|
+
rev: v8.1.0
|
|
117
117
|
hooks:
|
|
118
118
|
- id: complexipy
|
|
119
119
|
```
|
|
@@ -123,7 +123,7 @@ repos:
|
|
|
123
123
|
<details>
|
|
124
124
|
<summary><strong>🔌 VS Code Extension</strong></summary>
|
|
125
125
|
|
|
126
|
-
Install from the [
|
|
126
|
+
Install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rohaquinlop.complexipy) or [OpenVSX](https://open-vsx.org/extension/rohaquinlop/complexipy). It runs the complexipy language server, so install `complexipy` too (`uv tool install complexipy`). Inlay hints, hover, and warnings update as you type.
|
|
127
127
|
|
|
128
128
|
</details>
|
|
129
129
|
|
|
@@ -56,6 +56,7 @@ def file_complexity(
|
|
|
56
56
|
file_path: str,
|
|
57
57
|
check_script: bool = False,
|
|
58
58
|
no_ignore: bool = False,
|
|
59
|
+
with_plans: bool = True,
|
|
59
60
|
) -> FileComplexity:
|
|
60
61
|
"""Analyze the cognitive complexity of a single Python source file.
|
|
61
62
|
|
|
@@ -66,15 +67,16 @@ def file_complexity(
|
|
|
66
67
|
module-level (script) code as a '<module>' entry.
|
|
67
68
|
no_ignore: If True, disregard all '# complexipy: ignore' and
|
|
68
69
|
'# noqa: complexipy' comments, analyzing every function.
|
|
70
|
+
with_plans: If False, skip building refactor plans and leave every
|
|
71
|
+
'refactor_plans' list empty.
|
|
69
72
|
|
|
70
73
|
Returns:
|
|
71
74
|
FileComplexity object containing complete analysis results for the
|
|
72
75
|
file, including all functions found and their complexity scores.
|
|
73
76
|
|
|
74
77
|
Raises:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
SyntaxError: If the Python file contains syntax errors.
|
|
78
|
+
ValueError: If the file cannot be read, is not UTF-8 text, or
|
|
79
|
+
does not parse.
|
|
78
80
|
"""
|
|
79
81
|
path = Path(file_path).resolve()
|
|
80
82
|
cwd = Path.cwd().resolve()
|
|
@@ -89,4 +91,5 @@ def file_complexity(
|
|
|
89
91
|
base_path.as_posix(),
|
|
90
92
|
check_script,
|
|
91
93
|
no_ignore,
|
|
94
|
+
with_plans,
|
|
92
95
|
)
|
|
@@ -454,7 +454,10 @@ class RemovableIgnore:
|
|
|
454
454
|
"""The function's cognitive complexity measured without the ignore comment."""
|
|
455
455
|
|
|
456
456
|
def code_complexity(
|
|
457
|
-
code: str,
|
|
457
|
+
code: str,
|
|
458
|
+
check_script: bool = False,
|
|
459
|
+
no_ignore: bool = False,
|
|
460
|
+
with_plans: bool = True,
|
|
458
461
|
) -> CodeComplexity:
|
|
459
462
|
"""
|
|
460
463
|
Analyze cognitive complexity of Python code provided as a string.
|
|
@@ -472,13 +475,17 @@ def code_complexity(
|
|
|
472
475
|
code: A string containing valid Python source code. The code should
|
|
473
476
|
be properly formatted and syntactically correct. Syntax errors
|
|
474
477
|
will cause the analysis to fail.
|
|
478
|
+
check_script: Also report module-level code as a '<module>' entry.
|
|
479
|
+
no_ignore: Disregard inline ignore comments.
|
|
480
|
+
with_plans: Build refactor plans. When False, every
|
|
481
|
+
'refactor_plans' list is empty.
|
|
475
482
|
|
|
476
483
|
Returns:
|
|
477
484
|
CodeComplexity object containing the analysis results, including
|
|
478
485
|
individual function complexity scores and total complexity.
|
|
479
486
|
|
|
480
487
|
Raises:
|
|
481
|
-
|
|
488
|
+
ValueError: If the code does not parse, or on an internal error.
|
|
482
489
|
|
|
483
490
|
Example:
|
|
484
491
|
>>> code_sample = '''
|
|
@@ -511,6 +518,7 @@ def file_complexity(
|
|
|
511
518
|
base_path: str,
|
|
512
519
|
check_script: bool = False,
|
|
513
520
|
no_ignore: bool = False,
|
|
521
|
+
with_plans: bool = True,
|
|
514
522
|
) -> FileComplexity:
|
|
515
523
|
"""
|
|
516
524
|
Analyze cognitive complexity of a single Python source file.
|
|
@@ -531,16 +539,18 @@ def file_complexity(
|
|
|
531
539
|
in the analysis results. This is typically the project
|
|
532
540
|
root directory and affects the 'path' field in the
|
|
533
541
|
returned FileComplexity object.
|
|
542
|
+
check_script: Also report module-level code as a '<module>' entry.
|
|
543
|
+
no_ignore: Disregard inline ignore comments.
|
|
544
|
+
with_plans: Build refactor plans. When False, every
|
|
545
|
+
'refactor_plans' list is empty.
|
|
534
546
|
|
|
535
547
|
Returns:
|
|
536
548
|
FileComplexity object containing complete analysis results for the
|
|
537
549
|
file, including all functions found and their complexity scores.
|
|
538
550
|
|
|
539
551
|
Raises:
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
SyntaxError: If the Python file contains syntax errors.
|
|
543
|
-
UnicodeDecodeError: If the file cannot be decoded as text.
|
|
552
|
+
ValueError: If the file cannot be read, is not UTF-8 text, or does
|
|
553
|
+
not parse, or on an internal error.
|
|
544
554
|
|
|
545
555
|
Example:
|
|
546
556
|
>>> # Analyze a specific file
|
|
@@ -568,12 +578,18 @@ def run_cli(argv: List[str], invocation_path: Optional[str] = None) -> int:
|
|
|
568
578
|
|
|
569
579
|
Args:
|
|
570
580
|
argv: Command-line arguments, excluding the program name.
|
|
571
|
-
invocation_path:
|
|
572
|
-
|
|
581
|
+
invocation_path: Directory whose configuration file the run reads,
|
|
582
|
+
and under which it writes the cache, the snapshot, and the
|
|
583
|
+
reports; defaults to the current working directory. Relative
|
|
584
|
+
paths to analyze resolve against the process working
|
|
585
|
+
directory.
|
|
573
586
|
|
|
574
587
|
Returns:
|
|
575
588
|
Process exit code: 0 on success, 1 on gate failure, 2 on usage
|
|
576
589
|
errors.
|
|
590
|
+
|
|
591
|
+
Raises:
|
|
592
|
+
RuntimeError: On an internal error.
|
|
577
593
|
"""
|
|
578
594
|
...
|
|
579
595
|
|
|
@@ -589,6 +605,9 @@ def run_lsp() -> int:
|
|
|
589
605
|
|
|
590
606
|
Returns:
|
|
591
607
|
Process exit code: 0 after a clean shutdown, 1 otherwise.
|
|
608
|
+
|
|
609
|
+
Raises:
|
|
610
|
+
RuntimeError: On an internal error.
|
|
592
611
|
"""
|
|
593
612
|
...
|
|
594
613
|
|
|
@@ -600,9 +619,11 @@ def compute_diff(
|
|
|
600
619
|
"""
|
|
601
620
|
Compare the current complexity results against *git_ref*.
|
|
602
621
|
|
|
603
|
-
For each file in *current_files
|
|
604
|
-
*git_ref
|
|
605
|
-
|
|
622
|
+
For each file in *current_files* that is a regular file at
|
|
623
|
+
*git_ref*, retrieves its content there using ``git cat-file`` and
|
|
624
|
+
re-analyses it. A file that is not, such as a symbolic link at
|
|
625
|
+
*git_ref*, has no old version. Functions that appear only in one
|
|
626
|
+
version are marked NEW / REMOVED.
|
|
606
627
|
|
|
607
628
|
Args:
|
|
608
629
|
current_files: Complexity results of the current analysis.
|
|
@@ -614,6 +635,9 @@ def compute_diff(
|
|
|
614
635
|
List of DiffEntry objects, one per function that changed or is
|
|
615
636
|
new/removed. Unchanged functions are included so callers can
|
|
616
637
|
choose how to filter.
|
|
638
|
+
|
|
639
|
+
Raises:
|
|
640
|
+
ValueError: On an internal error.
|
|
617
641
|
"""
|
|
618
642
|
...
|
|
619
643
|
|
|
@@ -649,19 +673,25 @@ def collect_all_ignored_locations(
|
|
|
649
673
|
This is the backend for the --report-ignored CLI flag.
|
|
650
674
|
|
|
651
675
|
Args:
|
|
652
|
-
paths: List of file
|
|
676
|
+
paths: List of file and directory paths.
|
|
653
677
|
exclude: List of file/directory paths or globs to exclude from scanning.
|
|
654
|
-
invocation_path:
|
|
678
|
+
invocation_path: Directory that returned paths inside it are
|
|
679
|
+
relative to, and that exclude patterns also match against.
|
|
680
|
+
Relative paths to scan resolve against the process working
|
|
681
|
+
directory.
|
|
655
682
|
|
|
656
683
|
Returns:
|
|
657
684
|
A tuple of (ignored_locations, failed_paths) where:
|
|
658
685
|
- ignored_locations: List of IgnoredLocation objects, sorted by (path, line).
|
|
659
686
|
- failed_paths: List of paths that could not be processed.
|
|
660
687
|
|
|
688
|
+
Raises:
|
|
689
|
+
ValueError: On an internal error.
|
|
690
|
+
|
|
661
691
|
Example:
|
|
662
692
|
>>> locations, failed = collect_all_ignored_locations(
|
|
663
693
|
... paths=["/project/src"],
|
|
664
|
-
... exclude=["tests
|
|
694
|
+
... exclude=["tests/**"],
|
|
665
695
|
... )
|
|
666
696
|
>>> for loc in locations:
|
|
667
697
|
... print(f"{loc.path}:{loc.line} {loc.comment}")
|
|
@@ -687,21 +717,27 @@ def collect_removable_ignored_locations(
|
|
|
687
717
|
equal to `max_complexity_allowed`.
|
|
688
718
|
|
|
689
719
|
Args:
|
|
690
|
-
paths: List of file
|
|
720
|
+
paths: List of file and directory paths.
|
|
691
721
|
exclude: List of file/directory paths or globs to exclude from scanning.
|
|
692
722
|
max_complexity_allowed: Complexity threshold; markers suppressing
|
|
693
723
|
functions at or below this value are reported as removable.
|
|
694
|
-
invocation_path:
|
|
724
|
+
invocation_path: Directory that returned paths inside it are
|
|
725
|
+
relative to, and that exclude patterns also match against.
|
|
726
|
+
Relative paths to scan resolve against the process working
|
|
727
|
+
directory.
|
|
695
728
|
|
|
696
729
|
Returns:
|
|
697
730
|
A tuple of (removable_ignores, failed_paths) where:
|
|
698
731
|
- removable_ignores: List of RemovableIgnore objects, sorted by (path, line).
|
|
699
732
|
- failed_paths: List of paths that could not be processed.
|
|
700
733
|
|
|
734
|
+
Raises:
|
|
735
|
+
ValueError: On an internal error.
|
|
736
|
+
|
|
701
737
|
Example:
|
|
702
738
|
>>> removable, failed = collect_removable_ignored_locations(
|
|
703
739
|
... paths=["/project/src"],
|
|
704
|
-
... exclude=["tests
|
|
740
|
+
... exclude=["tests/**"],
|
|
705
741
|
... max_complexity_allowed=15,
|
|
706
742
|
... )
|
|
707
743
|
>>> for rem in removable:
|
|
@@ -12,7 +12,9 @@ word reserves the command line, so a path named ``lsp`` needs
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
+
import signal
|
|
15
16
|
import sys
|
|
17
|
+
import threading
|
|
16
18
|
from pathlib import Path
|
|
17
19
|
|
|
18
20
|
from complexipy._complexipy import run_cli, run_lsp
|
|
@@ -40,7 +42,14 @@ def lsp_shadow_warning() -> str | None:
|
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
def main() -> None:
|
|
43
|
-
"""Run the Rust CLI, or the language server for ``complexipy lsp``.
|
|
45
|
+
"""Run the Rust CLI, or the language server for ``complexipy lsp``.
|
|
46
|
+
|
|
47
|
+
Called from the main thread, Ctrl-C ends the process at once, also
|
|
48
|
+
while the Rust call runs. Called from another thread, it leaves the
|
|
49
|
+
SIGINT handler alone, since only the main thread can set it.
|
|
50
|
+
"""
|
|
51
|
+
if threading.current_thread() is threading.main_thread():
|
|
52
|
+
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
44
53
|
arguments = sys.argv[1:]
|
|
45
54
|
|
|
46
55
|
if arguments[:1] == [LSP_ARGUMENT]:
|
|
@@ -23,7 +23,7 @@ test = false
|
|
|
23
23
|
complexipy-core = { path = "../complexipy-core", features = ["config"] }
|
|
24
24
|
clap = { workspace = true }
|
|
25
25
|
serde = { workspace = true }
|
|
26
|
-
serde_json = { workspace = true }
|
|
26
|
+
serde_json = { workspace = true, features = ["raw_value"] }
|
|
27
27
|
toml = { workspace = true }
|
|
28
28
|
blake2 = { workspace = true }
|
|
29
29
|
sha2 = { workspace = true }
|
|
@@ -39,3 +39,6 @@ tempfile = { workspace = true }
|
|
|
39
39
|
complexipy-core = { path = "../complexipy-core", features = ["config", "schema"] }
|
|
40
40
|
schemars = { workspace = true }
|
|
41
41
|
jsonschema = { workspace = true }
|
|
42
|
+
|
|
43
|
+
[target.'cfg(any(target_os = "macos", target_os = "windows", all(target_os = "linux", target_arch = "x86_64")))'.dependencies]
|
|
44
|
+
mimalloc = "0.1.49"
|
|
@@ -128,3 +128,17 @@ fn plain_equals_form_parses() {
|
|
|
128
128
|
assert_eq!(cli.plain, Some(false));
|
|
129
129
|
assert_eq!(cli.paths, vec!["src"]);
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
#[test]
|
|
133
|
+
fn isolated_and_config_pin_the_config_source() {
|
|
134
|
+
let isolated = parse(&["complexipy", "--isolated", "src"]);
|
|
135
|
+
let named = parse(&["complexipy", "src", "--config", "ci.toml"]);
|
|
136
|
+
|
|
137
|
+
assert_eq!(isolated.isolated, Some(true));
|
|
138
|
+
assert_eq!(isolated.paths, vec!["src"]);
|
|
139
|
+
assert_eq!(named.config, Some("ci.toml".to_string()));
|
|
140
|
+
assert!(
|
|
141
|
+
CliArgs::try_parse_from(["complexipy", "src", "--isolated", "--config", "ci.toml"])
|
|
142
|
+
.is_err()
|
|
143
|
+
);
|
|
144
|
+
}
|
|
@@ -81,6 +81,12 @@ pub struct CliArgs {
|
|
|
81
81
|
|
|
82
82
|
#[arg(long, num_args = 0..=1, default_missing_value = "true", require_equals = true)]
|
|
83
83
|
pub report_ignored: Option<bool>,
|
|
84
|
+
|
|
85
|
+
#[arg(long, conflicts_with = "config", num_args = 0..=1, default_missing_value = "true", require_equals = true)]
|
|
86
|
+
pub isolated: Option<bool>,
|
|
87
|
+
|
|
88
|
+
#[arg(long, value_name = "PATH")]
|
|
89
|
+
pub config: Option<String>,
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
#[cfg(test)]
|
|
@@ -5,6 +5,14 @@ use clap::Parser;
|
|
|
5
5
|
use complexipy_cli::args::CliArgs;
|
|
6
6
|
use complexipy_cli::run::run_at;
|
|
7
7
|
|
|
8
|
+
#[cfg(any(
|
|
9
|
+
target_os = "macos",
|
|
10
|
+
target_os = "windows",
|
|
11
|
+
all(target_os = "linux", target_arch = "x86_64")
|
|
12
|
+
))]
|
|
13
|
+
#[global_allocator]
|
|
14
|
+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
15
|
+
|
|
8
16
|
fn main() -> ExitCode {
|
|
9
17
|
let invocation_path = std::env::current_dir()
|
|
10
18
|
.map(|path| path.to_string_lossy().into_owned())
|
|
@@ -3,6 +3,7 @@ use owo_colors::{OwoColorize, Stream, Style};
|
|
|
3
3
|
|
|
4
4
|
use crate::output::render::rule;
|
|
5
5
|
use complexipy_core::diff::{DiffEntry, DiffStatus};
|
|
6
|
+
use complexipy_core::sanitize::escape_controls;
|
|
6
7
|
|
|
7
8
|
pub fn format_diff(entries: &[DiffEntry], git_ref: &str) -> String {
|
|
8
9
|
let changed: Vec<&DiffEntry> = entries
|
|
@@ -19,7 +20,10 @@ pub fn format_diff(entries: &[DiffEntry], git_ref: &str) -> String {
|
|
|
19
20
|
.collect();
|
|
20
21
|
|
|
21
22
|
if changed.is_empty() {
|
|
22
|
-
return format!(
|
|
23
|
+
return format!(
|
|
24
|
+
"No functions changed relative to {}.",
|
|
25
|
+
escape_controls(git_ref)
|
|
26
|
+
);
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
let mut table = Table::new();
|
|
@@ -27,14 +31,21 @@ pub fn format_diff(entries: &[DiffEntry], git_ref: &str) -> String {
|
|
|
27
31
|
for entry in changed.iter().copied() {
|
|
28
32
|
table.add_row(vec![
|
|
29
33
|
Cell::new(status_style(&entry.status())),
|
|
30
|
-
Cell::new(format!(
|
|
34
|
+
Cell::new(format!(
|
|
35
|
+
"{}::{}",
|
|
36
|
+
escape_controls(&entry.file_path),
|
|
37
|
+
escape_controls(&entry.func_name)
|
|
38
|
+
)),
|
|
31
39
|
Cell::new(format_change(entry)),
|
|
32
40
|
]);
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
format!(
|
|
36
44
|
"\n{}\n{}\n\nNet: {}",
|
|
37
|
-
rule(&format!(
|
|
45
|
+
rule(&format!(
|
|
46
|
+
"Complexity diff (vs {})",
|
|
47
|
+
escape_controls(git_ref)
|
|
48
|
+
)),
|
|
38
49
|
table,
|
|
39
50
|
build_diff_summary(&changed)
|
|
40
51
|
)
|
|
@@ -183,3 +183,16 @@ fn empty_report_renders_empty_summary_and_no_fixes_message() {
|
|
|
183
183
|
assert_eq!(format_fix_diff("pkg/a.py", SOURCE, &empty, false), "");
|
|
184
184
|
assert_eq!(no_fixes_output(), "No fixes to apply.");
|
|
185
185
|
}
|
|
186
|
+
|
|
187
|
+
#[test]
|
|
188
|
+
fn diff_escapes_terminal_controls_from_the_source_with_and_without_color() {
|
|
189
|
+
let source = "def a():\n if x: # \u{1b}]0;TITLE\u{7}\n return 1\n";
|
|
190
|
+
|
|
191
|
+
for colored in [false, true] {
|
|
192
|
+
let rendered = format_fix_diff("pkg/\u{1b}[2Ja.py", source, &report(), colored);
|
|
193
|
+
|
|
194
|
+
assert!(!rendered.contains('\u{7}'), "colored = {colored}");
|
|
195
|
+
assert!(!rendered.contains("\u{1b}]0;"), "colored = {colored}");
|
|
196
|
+
assert!(!rendered.contains("\u{1b}[2J"), "colored = {colored}");
|
|
197
|
+
}
|
|
198
|
+
}
|