complexipy 0.3.2__tar.gz → 0.4.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.
@@ -17,54 +17,6 @@ dependencies = [
17
17
  "memchr",
18
18
  ]
19
19
 
20
- [[package]]
21
- name = "anstream"
22
- version = "0.6.11"
23
- source = "registry+https://github.com/rust-lang/crates.io-index"
24
- checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
25
- dependencies = [
26
- "anstyle",
27
- "anstyle-parse",
28
- "anstyle-query",
29
- "anstyle-wincon",
30
- "colorchoice",
31
- "utf8parse",
32
- ]
33
-
34
- [[package]]
35
- name = "anstyle"
36
- version = "1.0.6"
37
- source = "registry+https://github.com/rust-lang/crates.io-index"
38
- checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
39
-
40
- [[package]]
41
- name = "anstyle-parse"
42
- version = "0.2.3"
43
- source = "registry+https://github.com/rust-lang/crates.io-index"
44
- checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
45
- dependencies = [
46
- "utf8parse",
47
- ]
48
-
49
- [[package]]
50
- name = "anstyle-query"
51
- version = "1.0.2"
52
- source = "registry+https://github.com/rust-lang/crates.io-index"
53
- checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
54
- dependencies = [
55
- "windows-sys",
56
- ]
57
-
58
- [[package]]
59
- name = "anstyle-wincon"
60
- version = "3.0.2"
61
- source = "registry+https://github.com/rust-lang/crates.io-index"
62
- checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
63
- dependencies = [
64
- "anstyle",
65
- "windows-sys",
66
- ]
67
-
68
20
  [[package]]
69
21
  name = "anyhow"
70
22
  version = "1.0.79"
@@ -111,21 +63,13 @@ version = "1.0.0"
111
63
  source = "registry+https://github.com/rust-lang/crates.io-index"
112
64
  checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
113
65
 
114
- [[package]]
115
- name = "colorchoice"
116
- version = "1.0.0"
117
- source = "registry+https://github.com/rust-lang/crates.io-index"
118
- checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
119
-
120
66
  [[package]]
121
67
  name = "complexipy"
122
- version = "0.3.2"
68
+ version = "0.4.0"
123
69
  dependencies = [
124
70
  "csv",
125
- "env_logger",
126
71
  "ignore",
127
72
  "indicatif",
128
- "log",
129
73
  "pyo3",
130
74
  "rayon",
131
75
  "rustpython-parser",
@@ -240,29 +184,6 @@ version = "0.3.6"
240
184
  source = "registry+https://github.com/rust-lang/crates.io-index"
241
185
  checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
242
186
 
243
- [[package]]
244
- name = "env_filter"
245
- version = "0.1.0"
246
- source = "registry+https://github.com/rust-lang/crates.io-index"
247
- checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
248
- dependencies = [
249
- "log",
250
- "regex",
251
- ]
252
-
253
- [[package]]
254
- name = "env_logger"
255
- version = "0.11.1"
256
- source = "registry+https://github.com/rust-lang/crates.io-index"
257
- checksum = "05e7cf40684ae96ade6232ed84582f40ce0a66efcd43a5117aef610534f8e0b8"
258
- dependencies = [
259
- "anstream",
260
- "anstyle",
261
- "env_filter",
262
- "humantime",
263
- "log",
264
- ]
265
-
266
187
  [[package]]
267
188
  name = "errno"
268
189
  version = "0.3.8"
@@ -312,12 +233,6 @@ dependencies = [
312
233
  "regex-syntax",
313
234
  ]
314
235
 
315
- [[package]]
316
- name = "humantime"
317
- version = "2.1.0"
318
- source = "registry+https://github.com/rust-lang/crates.io-index"
319
- checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
320
-
321
236
  [[package]]
322
237
  name = "ignore"
323
238
  version = "0.4.22"
@@ -425,9 +340,9 @@ dependencies = [
425
340
 
426
341
  [[package]]
427
342
  name = "log"
428
- version = "0.4.20"
343
+ version = "0.4.21"
429
344
  source = "registry+https://github.com/rust-lang/crates.io-index"
430
- checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
345
+ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
431
346
 
432
347
  [[package]]
433
348
  name = "malachite"
@@ -746,18 +661,6 @@ dependencies = [
746
661
  "bitflags 1.3.2",
747
662
  ]
748
663
 
749
- [[package]]
750
- name = "regex"
751
- version = "1.10.3"
752
- source = "registry+https://github.com/rust-lang/crates.io-index"
753
- checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
754
- dependencies = [
755
- "aho-corasick",
756
- "memchr",
757
- "regex-automata",
758
- "regex-syntax",
759
- ]
760
-
761
664
  [[package]]
762
665
  name = "regex-automata"
763
666
  version = "0.4.5"
@@ -1079,12 +982,6 @@ version = "0.1.11"
1079
982
  source = "registry+https://github.com/rust-lang/crates.io-index"
1080
983
  checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c"
1081
984
 
1082
- [[package]]
1083
- name = "utf8parse"
1084
- version = "0.2.1"
1085
- source = "registry+https://github.com/rust-lang/crates.io-index"
1086
- checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
1087
-
1088
985
  [[package]]
1089
986
  name = "walkdir"
1090
987
  version = "2.4.0"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "complexipy"
3
- version = "0.3.2"
3
+ version = "0.4.0"
4
4
  edition = "2021"
5
5
  authors = ["Robin Quintero <rohaquinlop301@gmail.com>"]
6
6
  license = "MIT"
@@ -18,10 +18,8 @@ crate-type = ["cdylib"]
18
18
 
19
19
  [dependencies]
20
20
  csv = "1.3.0"
21
- env_logger = "0.11.1"
22
21
  ignore = "0.4.22"
23
22
  indicatif = "0.17.8"
24
- log = "0.4.20"
25
23
  pyo3 = "0.19.0"
26
24
  rayon = "1.8.1"
27
25
  rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: complexipy
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -144,7 +144,7 @@ The cognitive complexity of the file is 1, and the output of the command
144
144
  `complexipy path/to/file.py` will be:
145
145
 
146
146
  ```txt
147
- ───────────────────────────── 🐙 complexipy 0.3.2 ──────────────────────────────
147
+ ───────────────────────────── 🐙 complexipy 0.4.0 ──────────────────────────────
148
148
  Summary
149
149
  ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
150
150
  ┃ Path ┃ File ┃ Function ┃ Complexity ┃
@@ -126,7 +126,7 @@ The cognitive complexity of the file is 1, and the output of the command
126
126
  `complexipy path/to/file.py` will be:
127
127
 
128
128
  ```txt
129
- ───────────────────────────── 🐙 complexipy 0.3.2 ──────────────────────────────
129
+ ───────────────────────────── 🐙 complexipy 0.4.0 ──────────────────────────────
130
130
  Summary
131
131
  ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
132
132
  ┃ Path ┃ File ┃ Function ┃ Complexity ┃
@@ -28,7 +28,7 @@ import typer
28
28
  root_dir = Path(__file__).resolve().parent.parent
29
29
  app = typer.Typer(name="complexipy")
30
30
  console = Console()
31
- version = "0.3.2"
31
+ version = "0.4.0"
32
32
 
33
33
 
34
34
  @app.command()
@@ -126,7 +126,7 @@ The cognitive complexity of the file is 1, and the output of the command
126
126
  `complexipy path/to/file.py` will be:
127
127
 
128
128
  ```txt
129
- ───────────────────────────── 🐙 complexipy 0.3.2 ──────────────────────────────
129
+ ───────────────────────────── 🐙 complexipy 0.4.0 ──────────────────────────────
130
130
  Summary
131
131
  ┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
132
132
  ┃ Path ┃ File ┃ Function ┃ Complexity ┃
@@ -271,47 +271,44 @@ fn statement_cognitive_complexity(statement: Stmt, nesting_level: u64) -> PyResu
271
271
  }
272
272
  }
273
273
  Stmt::Assign(a) => {
274
- match *a.value {
275
- ast::Expr::IfExp(..) => {
276
- complexity += count_bool_ops(*a.value);
277
- }
278
- _ => {}
279
- }
280
-
281
- if complexity > 0 {
282
- complexity += nesting_level;
283
- }
274
+ complexity += count_bool_ops(*a.value, nesting_level);
284
275
  }
285
276
  Stmt::For(f) => {
286
277
  complexity += 1 + nesting_level;
287
278
  for node in f.body.iter() {
288
279
  complexity += statement_cognitive_complexity(node.clone(), nesting_level + 1)?;
289
280
  }
281
+
282
+ complexity += count_bool_ops(*f.iter, nesting_level);
290
283
  }
291
284
  Stmt::While(w) => {
292
285
  complexity += 1 + nesting_level;
293
- complexity += count_bool_ops(*w.test);
286
+ complexity += count_bool_ops(*w.test, nesting_level);
294
287
  for node in w.body.iter() {
295
288
  complexity += statement_cognitive_complexity(node.clone(), nesting_level + 1)?;
296
289
  }
297
290
  }
298
291
  Stmt::If(i) => {
299
292
  complexity += 1 + nesting_level;
300
- complexity += count_bool_ops(*i.test);
293
+ complexity += count_bool_ops(*i.test, nesting_level);
301
294
  for node in i.body.iter() {
302
295
  complexity += statement_cognitive_complexity(node.clone(), nesting_level + 1)?;
303
296
  }
304
297
 
305
- let mut orelse_complexity: u64 = 0;
306
- for node in i.orelse.iter() {
307
- orelse_complexity += statement_cognitive_complexity(node.clone(), nesting_level)?;
308
- }
298
+ let orelse_complexities: Vec<u64> = i
299
+ .orelse
300
+ .iter()
301
+ .map(|node| statement_cognitive_complexity(node.clone(), nesting_level))
302
+ .filter(|complexity| complexity.is_ok())
303
+ .filter(|complexity| *complexity.as_ref().unwrap() > 0)
304
+ .map(|complexity| complexity.unwrap())
305
+ .collect();
309
306
 
310
- if orelse_complexity > 0 && i.orelse.len() > 0 {
311
- complexity -= (nesting_level) * i.orelse.len() as u64;
307
+ let orelse_complexity: u64 = orelse_complexities.iter().sum();
308
+
309
+ if orelse_complexities.len() > 0 {
312
310
  complexity += orelse_complexity;
313
- } else if i.orelse.len() > 0 {
314
- complexity += 1;
311
+ complexity -= (nesting_level) * orelse_complexities.len() as u64;
315
312
  }
316
313
  }
317
314
  Stmt::Try(t) => {
@@ -130,30 +130,60 @@ pub fn is_decorator(statement: Stmt) -> bool {
130
130
  ans
131
131
  }
132
132
 
133
- pub fn count_bool_ops(expr: ast::Expr) -> u64 {
133
+ pub fn count_bool_ops(expr: ast::Expr, nesting_level: u64) -> u64 {
134
134
  let mut complexity: u64 = 0;
135
135
 
136
136
  match expr {
137
137
  ast::Expr::BoolOp(b) => {
138
138
  complexity += 1;
139
139
  for value in b.values.iter() {
140
- complexity += count_bool_ops(value.clone());
140
+ complexity += count_bool_ops(value.clone(), nesting_level);
141
141
  }
142
142
  }
143
143
  ast::Expr::UnaryOp(u) => {
144
- complexity += count_bool_ops(*u.operand);
144
+ complexity += count_bool_ops(*u.operand, nesting_level);
145
145
  }
146
146
  ast::Expr::Compare(c) => {
147
- complexity += count_bool_ops(*c.left);
147
+ complexity += count_bool_ops(*c.left, nesting_level);
148
148
  for comparator in c.comparators.iter() {
149
- complexity += count_bool_ops(comparator.clone());
149
+ complexity += count_bool_ops(comparator.clone(), nesting_level);
150
150
  }
151
151
  }
152
152
  ast::Expr::IfExp(i) => {
153
- complexity += 1;
154
- complexity += count_bool_ops(*i.test);
155
- complexity += count_bool_ops(*i.body);
156
- complexity += count_bool_ops(*i.orelse);
153
+ complexity += 1 + nesting_level;
154
+ complexity += count_bool_ops(*i.test, nesting_level);
155
+ complexity += count_bool_ops(*i.body, nesting_level);
156
+ complexity += count_bool_ops(*i.orelse, nesting_level);
157
+ }
158
+ ast::Expr::Call(c) => {
159
+ for arg in c.args.iter() {
160
+ complexity += count_bool_ops(arg.clone(), nesting_level);
161
+ }
162
+ }
163
+ ast::Expr::Tuple(t) => {
164
+ for element in t.elts.iter() {
165
+ complexity += count_bool_ops(element.clone(), nesting_level);
166
+ }
167
+ }
168
+ ast::Expr::List(l) => {
169
+ for element in l.elts.iter() {
170
+ complexity += count_bool_ops(element.clone(), nesting_level);
171
+ }
172
+ }
173
+ ast::Expr::Set(s) => {
174
+ for element in s.elts.iter() {
175
+ complexity += count_bool_ops(element.clone(), nesting_level);
176
+ }
177
+ }
178
+ ast::Expr::Dict(d) => {
179
+ for key in d.keys.iter() {
180
+ if let Some(key_value) = key {
181
+ complexity += count_bool_ops(key_value.clone(), nesting_level);
182
+ }
183
+ }
184
+ for value in d.values.iter() {
185
+ complexity += count_bool_ops(value.clone(), nesting_level);
186
+ }
157
187
  }
158
188
  _ => {}
159
189
  }
File without changes
File without changes
File without changes
File without changes
File without changes