Coverage for debputy/plugins/grantlee.py: 95%

30 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-09-07 09:27 +0000

1import re 

2from typing import Optional 

3 

4from debputy.plugin.api import ( 

5 BinaryCtrlAccessor, 

6 PackageProcessingContext, 

7 VirtualPath, 

8 define_debputy_plugin, 

9) 

10from debputy.util import _error 

11 

12_RE_GRANTLEE_VERSION = re.compile(r"^\d\.\d$") 

13 

14 

15plugin_definition = define_debputy_plugin() 

16 

17 

18@plugin_definition.metadata_or_maintscript_detector 

19def detect_grantlee_dependencies( 

20 fs_root: VirtualPath, 

21 ctrl: BinaryCtrlAccessor, 

22 context: PackageProcessingContext, 

23) -> None: 

24 binary_package = context.binary_package 

25 if binary_package.is_arch_all: 

26 # Delta from dh_grantlee, but the MULTIARCH paths should not 

27 # exist in arch:all packages 

28 return 

29 ma = binary_package.package_deb_architecture_variable("MULTIARCH") 

30 grantlee_root_dirs = [ 

31 f"usr/lib/{ma}/grantlee", 

32 f"usr/lib/{ma}/qt5/plugins/grantlee", 

33 ] 

34 grantee_version: Optional[str] = None 

35 for grantlee_root_dir in grantlee_root_dirs: 

36 grantlee_root_path = fs_root.lookup(grantlee_root_dir) 

37 if grantlee_root_path is None or not grantlee_root_path.is_dir: 

38 continue 

39 # Delta: The original code recurses and then checks for "grantee/VERSION". 

40 # Code here assumes that was just File::Find being used as a dir iterator. 

41 for child in grantlee_root_path.iterdir: 

42 if not _RE_GRANTLEE_VERSION.fullmatch(child.name): 

43 continue 

44 version = child.name 

45 if grantee_version is not None and version != grantee_version: 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true

46 _error( 

47 f"Package {binary_package.name} contains plugins for different grantlee versions" 

48 ) 

49 grantee_version = version 

50 

51 if grantee_version is None: 

52 return 

53 dep_version = grantee_version.replace(".", "-") 

54 grantee_dep = f"grantlee5-templates-{dep_version}" 

55 ctrl.substvars["grantlee:Depends"] = grantee_dep