Coverage for analyzers/python.py: 93%

1"""Python source file analyzer -- assembles all metrics."""

2

3 from __future__ import annotations

4

5 from analyzers.shared import create_analyzer_file_fn, create_analyzer_source_fn

6 from parsers.python import parse, collect_functions, func_name

7 from patterns.python import check_patterns

8 from metrics.lloc.python import count_lloc

9 from metrics.halstead.python import compute_halstead_py

10 from metrics.npath.python import compute_npath_py

11 from metrics.dtd.python import compute_dtd_py

12 from metrics.cognitive.python import compute_cognitive_py

13 from metrics.cyclomatic.python import compute_cyclomatic_py

14 from metrics.duplication.config import PYTHON_CONFIG

15

16 analyze_source = create_analyzer_source_fn(

17 parse_fn=parse,

18 collect_functions_fn=collect_functions,

19 func_name_fn=func_name,

20 compute_cognitive_fn=compute_cognitive_py,

21 compute_halstead_fn=compute_halstead_py,

22 compute_npath_fn=compute_npath_py,

23 compute_dtd_fn=compute_dtd_py,

24 compute_cyclomatic_fn=compute_cyclomatic_py,

25 count_lloc_fn=count_lloc,

26 dup_config=PYTHON_CONFIG,

27 check_patterns_fn=check_patterns,

28)

29

30

31 def analyze_file(filepath, timing_manager=None):

32 """Analyze a Python file and return cognitive complexity scores."""

33 return create_analyzer_file_fn(analyze_source)(

34 filepath, timing_manager=timing_manager

35 )