complexipy 8.1.0__cp315-cp315-win32.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.
complexipy/__init__.py ADDED
@@ -0,0 +1,92 @@
1
+ """complexipy - cognitive complexity analyzer for Python.
2
+
3
+ The analysis engine, the diff comparison, and the ratchet gates are
4
+ implemented in Rust and exposed through the ``complexipy._complexipy``
5
+ extension module. This package is a thin re-export layer only.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+
12
+ import complexipy._complexipy as _complexipy
13
+ from complexipy._complexipy import (
14
+ Applicability,
15
+ CodeComplexity,
16
+ CodeSuggestion,
17
+ DiffEntry,
18
+ DiffStatus,
19
+ FileComplexity,
20
+ FunctionComplexity,
21
+ IgnoredLocation,
22
+ LineComplexity,
23
+ RefactorPlan,
24
+ RemovableIgnore,
25
+ RuleCategory,
26
+ code_complexity,
27
+ collect_all_ignored_locations,
28
+ collect_removable_ignored_locations,
29
+ compute_diff,
30
+ has_regressions,
31
+ )
32
+
33
+ __all__ = [
34
+ "Applicability",
35
+ "CodeComplexity",
36
+ "CodeSuggestion",
37
+ "DiffEntry",
38
+ "DiffStatus",
39
+ "FileComplexity",
40
+ "FunctionComplexity",
41
+ "IgnoredLocation",
42
+ "LineComplexity",
43
+ "RefactorPlan",
44
+ "RemovableIgnore",
45
+ "RuleCategory",
46
+ "code_complexity",
47
+ "collect_all_ignored_locations",
48
+ "collect_removable_ignored_locations",
49
+ "compute_diff",
50
+ "file_complexity",
51
+ "has_regressions",
52
+ ]
53
+
54
+
55
+ def file_complexity(
56
+ file_path: str,
57
+ check_script: bool = False,
58
+ no_ignore: bool = False,
59
+ ) -> FileComplexity:
60
+ """Analyze the cognitive complexity of a single Python source file.
61
+
62
+ Args:
63
+ file_path: Path to the Python file to analyze. Can be relative or
64
+ absolute. The file must exist and be readable.
65
+ check_script: If True, also report cognitive complexity of
66
+ module-level (script) code as a '<module>' entry.
67
+ no_ignore: If True, disregard all '# complexipy: ignore' and
68
+ '# noqa: complexipy' comments, analyzing every function.
69
+
70
+ Returns:
71
+ FileComplexity object containing complete analysis results for the
72
+ file, including all functions found and their complexity scores.
73
+
74
+ Raises:
75
+ FileNotFoundError: If the specified file does not exist.
76
+ PermissionError: If the file cannot be read due to permissions.
77
+ SyntaxError: If the Python file contains syntax errors.
78
+ """
79
+ path = Path(file_path).resolve()
80
+ cwd = Path.cwd().resolve()
81
+ try:
82
+ path.relative_to(cwd)
83
+ except ValueError:
84
+ base_path = path.parent
85
+ else:
86
+ base_path = cwd
87
+ return _complexipy.file_complexity(
88
+ path.as_posix(),
89
+ base_path.as_posix(),
90
+ check_script,
91
+ no_ignore,
92
+ )
Binary file