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

39 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2026-01-26 19:30 +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, PackageTypeSelector 

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_types=PackageTypeSelector.DEB 

25 | PackageTypeSelector.UDEB, 

26) 

27def gnome_versions( 

28 _unused: Any, 

29 ctrl: BinaryCtrlAccessor, 

30 context: PackageProcessingContext, 

31) -> None: 

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

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

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

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

36 version = context.binary_package_version 

37 m = GNOME_VERSION1_RE.match(version) 

38 epoch = "" 

39 gnome_version = "" 

40 gnome_next_version = "" 

41 if m: 

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

43 if major_version < 40: 

44 epoch = m.group(1) 

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

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

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

48 prefix = "" 

49 else: 

50 prefix = f"{major_version}." 

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

52 if gnome_version == "": 

53 m = GNOME_VERSION2_RE.match(version) 

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

55 _error( 

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

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

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

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

60 ) 

61 epoch = m.group(1) 

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

63 gnome_version = f"{version}~" 

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

65 if epoch is None: 

66 epoch = "" 

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

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

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

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