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

38 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-07 12:14 +0200

1import re 

2from typing import Any 

3 

4from debputy.plugin.api import ( 

5 DebputyPluginInitializer, 

6 BinaryCtrlAccessor, 

7 PackageProcessingContext, 

8) 

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 

17def initialize(api: DebputyPluginInitializer) -> None: 

18 api.metadata_or_maintscript_detector( 

19 "gnome-versions", 

20 gnome_versions, 

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

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

23 ) 

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

25 # feature. 

26 

27 

28def gnome_versions( 

29 _unused: Any, 

30 ctrl: BinaryCtrlAccessor, 

31 context: PackageProcessingContext, 

32) -> None: 

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

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

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

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

37 version = context.binary_package_version 

38 m = GNOME_VERSION1_RE.match(version) 

39 epoch = "" 

40 gnome_version = "" 

41 gnome_next_version = "" 

42 if m: 

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

44 if major_version < 40: 

45 epoch = m.group(1) 

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

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

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

49 prefix = "" 

50 else: 

51 prefix = f"{major_version}." 

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

53 if gnome_version == "": 

54 m = GNOME_VERSION2_RE.match(version) 

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

56 _error( 

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

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

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

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

61 ) 

62 epoch = m.group(1) 

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

64 gnome_version = f"{version}~" 

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

66 if epoch is None: 

67 epoch = "" 

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

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

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

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