Coverage for debputy/plugins/gnome.py: 96%

39 statements  

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

1import re 

2from typing import Any 

3 

4from debputy.plugin.api import ( 

5 BinaryCtrlAccessor, 

6 PackageProcessingContext, 

7) 

8from debputy.plugin.api import define_debputy_plugin 

9from debputy.util import _error 

10 

11GNOME_VERSION1_RE = re.compile(r"^(\d+:)?(\d+)\.(\d+)\.[\d.]+.*$") 

12GNOME_VERSION2_RE = re.compile( 

13 r"^(\d+:)?(\d+)(?:\.[\d.]+|~(alpha|beta|rc)[\d.]*|[+~])?.*$" 

14) 

15 

16 

17# Looking for "clean_la_files"? The `debputy` plugin provides a replacement 

18# feature. 

19plugin_definition = define_debputy_plugin() 

20 

21 

22@plugin_definition.metadata_or_maintscript_detector( 

23 # Probably not necessary, but this is the most faithful conversion 

24 package_type=["deb", "udeb"], 

25) 

26def gnome_versions( 

27 _unused: Any, 

28 ctrl: BinaryCtrlAccessor, 

29 context: PackageProcessingContext, 

30) -> None: 

31 # Conversion note: In debhelper, $dh{VERSION} is actually the "source" version 

32 # (though sometimes it has a binNMU version too). In `debputy`, we have access 

33 # to the "true" binary version (dpkg-gencontrol -v<VERSION>). In 99% of all cases, 

34 # the difference is irrelevant as people rarely use dpkg-gencontrol -v<VERSION>. 

35 version = context.binary_package_version 

36 m = GNOME_VERSION1_RE.match(version) 

37 epoch = "" 

38 gnome_version = "" 

39 gnome_next_version = "" 

40 if m: 

41 major_version = int(m.group(2)) 

42 if major_version < 40: 

43 epoch = m.group(1) 

44 minor_version = int(m.group(3)) 

45 gnome_version = f"{major_version}.{minor_version}" 

46 if major_version == 3 and minor_version == 38: 

47 prefix = "" 

48 else: 

49 prefix = f"{major_version}." 

50 gnome_next_version = f"{prefix}{minor_version + 2}" 

51 if gnome_version == "": 

52 m = GNOME_VERSION2_RE.match(version) 

53 if not m: 53 ↛ 54line 53 didn't jump to line 54 because the condition on line 53 was never true

54 _error( 

55 f"Unable to determine the GNOME major version from {version} for package" 

56 f" {context.binary_package.name}. If this is not a GNOME package or it does" 

57 f" not follow the GNOME version standard, please disable the GNOME plugin" 

58 f" (debputy-plugin-gnome)." 

59 ) 

60 epoch = m.group(1) 

61 version = int(m.group(2)) 

62 gnome_version = f"{version}~" 

63 gnome_next_version = f"{version + 1}~" 

64 if epoch is None: 

65 epoch = "" 

66 ctrl.substvars["gnome:Version"] = f"{epoch}{gnome_version}" 

67 ctrl.substvars["gnome:UpstreamVersion"] = f"{gnome_version}" 

68 ctrl.substvars["gnome:NextVersion"] = f"{epoch}{gnome_next_version}" 

69 ctrl.substvars["gnome:NextUpstreamVersion"] = f"{gnome_next_version}"