Coverage for src/debputy/manifest_parser/parser_data.py: 85%

54 statements  

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

1import contextlib 

2from typing import ( 

3 Iterator, 

4 Optional, 

5 Mapping, 

6 NoReturn, 

7 Union, 

8 Any, 

9 TYPE_CHECKING, 

10 Tuple, 

11) 

12 

13from debian.debian_support import DpkgArchTable 

14 

15from debputy._deb_options_profiles import DebBuildOptionsAndProfiles 

16from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable 

17from debputy.manifest_conditions import ManifestCondition 

18from debputy.manifest_parser.exceptions import ManifestParseException 

19from debputy.manifest_parser.util import AttributePath 

20from debputy.packages import BinaryPackage 

21from debputy.plugin.api.impl_types import ( 

22 _ALL_PACKAGE_TYPES, 

23 resolve_package_type_selectors, 

24 TP, 

25 DispatchingTableParser, 

26 TTP, 

27 DispatchingObjectParser, 

28) 

29from debputy.plugin.api.spec import PackageTypeSelector 

30from debputy.substitution import Substitution 

31 

32 

33if TYPE_CHECKING: 

34 from debputy.highlevel_manifest import PackageTransformationDefinition 

35 

36 

37class ParserContextData: 

38 @property 

39 def binary_packages(self) -> Mapping[str, BinaryPackage]: 

40 raise NotImplementedError 

41 

42 @property 

43 def _package_states(self) -> Mapping[str, "PackageTransformationDefinition"]: 

44 raise NotImplementedError 

45 

46 @property 

47 def is_single_binary_package(self) -> bool: 

48 return len(self.binary_packages) == 1 

49 

50 def single_binary_package( 

51 self, 

52 attribute_path: AttributePath, 

53 *, 

54 package_type: PackageTypeSelector = _ALL_PACKAGE_TYPES, 

55 package_attribute: Optional[str] = None, 

56 ) -> Optional[BinaryPackage]: 

57 resolved_package_types = resolve_package_type_selectors(package_type) 

58 possible_matches = [ 

59 p 

60 for p in self.binary_packages.values() 

61 if p.package_type in resolved_package_types 

62 ] 

63 if len(possible_matches) == 1: 63 ↛ 66line 63 didn't jump to line 66, because the condition on line 63 was never false

64 return possible_matches[0] 

65 

66 if package_attribute is not None: 

67 raise ManifestParseException( 

68 f"The {attribute_path.path} rule needs the attribute `{package_attribute}`" 

69 " for this source package." 

70 ) 

71 

72 if not possible_matches: 

73 _package_types = ", ".join(sorted(resolved_package_types)) 

74 raise ManifestParseException( 

75 f"The {attribute_path.path} rule is not applicable to this source package" 

76 f" (it only applies to source packages that builds exactly one of" 

77 f" the following package types: {_package_types})." 

78 ) 

79 raise ManifestParseException( 

80 f"The {attribute_path.path} rule is not applicable to multi-binary packages." 

81 ) 

82 

83 def _error(self, msg: str) -> "NoReturn": 

84 raise ManifestParseException(msg) 

85 

86 def is_known_package(self, package_name: str) -> bool: 

87 return package_name in self._package_states 

88 

89 def binary_package_data( 

90 self, 

91 package_name: str, 

92 ) -> "PackageTransformationDefinition": 

93 if package_name not in self._package_states: 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true

94 self._error( 

95 f'The package "{package_name}" is not present in the debian/control file (could not find' 

96 f' "Package: {package_name}" in a binary stanza) nor is it a -dbgsym package for one' 

97 " for a package in debian/control." 

98 ) 

99 return self._package_states[package_name] 

100 

101 @property 

102 def dpkg_architecture_variables(self) -> DpkgArchitectureBuildProcessValuesTable: 

103 raise NotImplementedError 

104 

105 @property 

106 def dpkg_arch_query_table(self) -> DpkgArchTable: 

107 raise NotImplementedError 

108 

109 @property 

110 def build_env(self) -> DebBuildOptionsAndProfiles: 

111 raise NotImplementedError 

112 

113 @contextlib.contextmanager 

114 def binary_package_context( 

115 self, 

116 package_name: str, 

117 ) -> Iterator["PackageTransformationDefinition"]: 

118 raise NotImplementedError 

119 

120 @property 

121 def substitution(self) -> Substitution: 

122 raise NotImplementedError 

123 

124 @property 

125 def current_binary_package_state(self) -> "PackageTransformationDefinition": 

126 raise NotImplementedError 

127 

128 @property 

129 def is_in_binary_package_state(self) -> bool: 

130 raise NotImplementedError 

131 

132 def dispatch_parser_table_for(self, rule_type: TTP) -> DispatchingTableParser[TP]: 

133 raise NotImplementedError