Coverage for bim2sim/utilities/check_docstrings.py: 0%

39 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-12 13:34 +0000

1import re 

2from pathlib import Path 

3import subprocess 

4import bim2sim 

5 

6 

7def count_functions_with_correct_docstrings(directory): 

8 """Check how many functions have no docstrings and structure the output in a dict.""" 

9 result = subprocess.run(['pydocstyle', directory], capture_output=True, text=True) 

10 output = result.stdout 

11 

12 output_list = output.splitlines() 

13 

14 functions_without_docstrings = 0 

15 last_function_index = 0 

16 structured_messages = {} 

17 pattern = r'D\d{3}:' 

18 for i, line in enumerate(output_list): 

19 

20 # error indicators are always starting with "DXXX:" 

21 matches = [match[:-1] for match in re.findall(pattern, line)] 

22 if matches: 

23 error_msg = line 

24 file_msg = str(output_list[last_function_index:i]) 

25 last_function_index = i+1 

26 # ignore aixlib submodule 

27 if r"\\plugins\\AixLib\\" in file_msg: 

28 continue 

29 functions_without_docstrings += 1 

30 structured_messages[file_msg] = error_msg 

31 

32 return functions_without_docstrings, structured_messages 

33 

34 

35def generate_markdown_table(data): 

36 max_line_length = 100 

37 table = "| done | Function | Error |\n|------|---------------------------|-------|\n" 

38 

39 for key, value in data.items(): 

40 key = key.replace("|", "\\|") # Ersetze "|" durch "\|" 

41 

42 # Entferne den angegebenen Teilstring, falls vorhanden 

43 key = key.split('bim2sim', 1)[-1].strip() 

44 

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', ' ') 

48 

49 value = value.replace("|", "\\|") # Ersetze "|" durch "\|" 

50 table += f"| [ ] | {key.ljust(26)} | {value} |\n" 

51 

52 return table 

53 

54 

55if __name__ == '__main__': 

56 # run the function against current bim2sim repository 

57 functions_with_docstrings, structured_messages = count_functions_with_correct_docstrings(Path(bim2sim.__file__).parent) 

58 markdown_table = generate_markdown_table(structured_messages) 

59 print(f'Number of cuntions with Docstrings: {functions_with_docstrings}') 

60 

61 print(markdown_table)