Coverage for src/debputy/plugins/debputy/discard_rules.py: 96%

38 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2026-09-06 13:40 +0000

1import re 

2 

3from debputy.plugin.api import VirtualPath 

4 

5_VCS_PATHS = { 

6 ".arch-inventory", 

7 ".arch-ids", 

8 ".be", 

9 ".bzrbackup", 

10 ".bzrignore", 

11 ".bzrtags", 

12 ".cvsignore", 

13 ".hg", 

14 ".hgignore", 

15 ".hgtags", 

16 ".hgsigs", 

17 ".git", 

18 ".gitignore", 

19 ".gitattributes", 

20 ".gitmodules", 

21 ".gitreview", 

22 ".mailmap", 

23 ".mtn-ignore", 

24 ".svn", 

25 "{arch}", 

26 "CVS", 

27 "RCS", 

28 "_MTN", 

29 "_darcs", 

30} 

31 

32_BACKUP_FILES_RE = re.compile( 

33 "|".join( 

34 [ 

35 # Common backup files 

36 r".*~", 

37 r".*[.](?:bak|orig|rej)", 

38 # Editor backup/swap files 

39 r"[.]#.*", 

40 r"[.].*[.]sw.", 

41 # Other known stuff 

42 r"[.]shelf", 

43 r",,.*", # "baz-style junk" (according to dpkg (Dpkg::Source::Package) 

44 r"DEADJOE", # Joe's one line of immortality that just gets cargo cult'ed around ... just in case. 

45 ] 

46 ) 

47) 

48 

49_DOXYGEN_DIR_TEST_FILES = ["doxygen.css", "doxygen.svg", "index.html"] 

50 

51 

52def _debputy_discard_python_cache_files(path: "VirtualPath") -> bool: 

53 if path.name in ("__pycache__", ".pdm-build", ".pytest_cache") and path.is_dir: 

54 return True 

55 if path.is_file and path.name == ".coverage": 

56 return True 

57 return path.name.endswith((".pyc", ".pyo")) and path.is_file 

58 

59 

60def _debputy_prune_la_files(path: "VirtualPath") -> bool: 

61 return ( 

62 path.name.endswith(".la") 

63 and path.is_file 

64 and path.absolute.startswith("/usr/lib") 

65 ) 

66 

67 

68def _debputy_prune_backup_files(path: VirtualPath) -> bool: 

69 return bool(_BACKUP_FILES_RE.match(path.name)) 

70 

71 

72def _debputy_prune_vcs_paths(path: VirtualPath) -> bool: 

73 return path.name in _VCS_PATHS 

74 

75 

76def _debputy_prune_info_dir_file(path: VirtualPath) -> bool: 

77 return path.absolute == "/usr/share/info/dir" 

78 

79 

80def _debputy_prune_binary_debian_dir(path: VirtualPath) -> bool: 

81 return path.absolute == "/DEBIAN" 

82 

83 

84def _debputy_prune_doxygen_cruft(path: VirtualPath) -> bool: 

85 if not path.name.endswith((".md5", ".map")) or not path.is_file: 

86 return False 

87 current_path = path 

88 while not current_path.is_root_dir(): 88 ↛ 101line 88 didn't jump to line 101 because the condition on line 88 was always true

89 parent_dir = current_path.parent_dir 

90 assert parent_dir is not None # type hint (implied by is_root_dir) 

91 is_doxygen_dir = True 

92 for name in _DOXYGEN_DIR_TEST_FILES: 

93 test_file = parent_dir.get(name) 

94 if test_file is None or not test_file.is_file: 

95 is_doxygen_dir = False 

96 break 

97 

98 if is_doxygen_dir: 

99 return True 

100 current_path = parent_dir 

101 return False