Coverage for bim2sim/utilities/check_docstrings.py: 0%
38 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 17:09 +0000
1import re
2from pathlib import Path
3import subprocess
4import bim2sim
6def count_functions_with_correct_docstrings(directory):
7 """Check how many functions have no docstrings and structure the output in a dict."""
8 result = subprocess.run(['pydocstyle', directory], capture_output=True, text=True)
9 output = result.stdout
11 output_list = output.splitlines()
13 functions_without_docstrings = 0
14 last_function_index = 0
15 structured_messages = {}
16 pattern = r'D\d{3}:'
17 for i, line in enumerate(output_list):
19 # error indicators are always starting with "DXXX:"
20 matches = [match[:-1] for match in re.findall(pattern, line)]
21 if matches:
22 error_msg = line
23 file_msg = str(output_list[last_function_index:i])
24 last_function_index = i+1
25 # ignore aixlib submodule
26 if r"\\plugins\\AixLib\\" in file_msg:
27 continue
28 functions_without_docstrings += 1
29 structured_messages[file_msg] = error_msg
32 return functions_without_docstrings, structured_messages
35def generate_markdown_table(data):
36 max_line_length = 100
37 table = "| done | Function | Error |\n|------|---------------------------|-------|\n"
39 for key, value in data.items():
40 key = key.replace("|", "\\|") # Ersetze "|" durch "\|"
42 # Entferne den angegebenen Teilstring, falls vorhanden
43 key = key.split('bim2sim', 1)[-1].strip()
45 # Füge Zeilenumbrüche in die erste Spalte ein, wenn nötig
46 key_lines = [key[i:i + max_line_length] for i in range(0, len(key), max_line_length)]
47 key = " \n".join(key_lines).replace('\n', ' ')
49 value = value.replace("|", "\\|") # Ersetze "|" durch "\|"
50 table += f"| [ ] | {key.ljust(26)} | {value} |\n"
52 return table
55# run the function against current bim2sim repository
56functions_with_docstrings, structured_messages = count_functions_with_correct_docstrings(Path(bim2sim.__file__).parent)
57markdown_table = generate_markdown_table(structured_messages)
58print(f'Number of cuntions with Docstrings: {functions_with_docstrings}')
60print(markdown_table)