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

58 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2025-01-27 13:59 +0000

1import contextlib 

2from typing import ( 

3 Iterator, 

4 Optional, 

5 Mapping, 

6 NoReturn, 

7 TYPE_CHECKING, 

8) 

9 

10from debian.debian_support import DpkgArchTable 

11 

12from debputy._deb_options_profiles import DebBuildOptionsAndProfiles 

13from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable 

14from debputy.manifest_parser.base_types import BuildEnvironmentDefinition 

15from debputy.manifest_parser.exceptions import ManifestParseException 

16from debputy.manifest_parser.util import AttributePath 

17from debputy.manifest_parser.util import ( 

18 _ALL_PACKAGE_TYPES, 

19 resolve_package_type_selectors, 

20) 

21from debputy.packages import BinaryPackage 

22from debputy.plugin.api.impl_types import ( 

23 TP, 

24 DispatchingTableParser, 

25 TTP, 

26) 

27from debputy.plugin.api.spec import PackageTypeSelector, DebputyIntegrationMode 

28from debputy.substitution import Substitution 

29 

30if TYPE_CHECKING: 

31 from debputy.highlevel_manifest import PackageTransformationDefinition 

32 

33 

34class ParserContextData: 

35 @property 

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

37 raise NotImplementedError 

38 

39 @property 

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

41 raise NotImplementedError 

42 

43 @property 

44 def is_single_binary_package(self) -> bool: 

45 return len(self.binary_packages) == 1 

46 

47 def single_binary_package( 

48 self, 

49 attribute_path: AttributePath, 

50 *, 

51 package_type: PackageTypeSelector = _ALL_PACKAGE_TYPES, 

52 package_attribute: Optional[str] = None, 

53 ) -> Optional[BinaryPackage]: 

54 resolved_package_types = resolve_package_type_selectors(package_type) 

55 possible_matches = [ 

56 p 

57 for p in self.binary_packages.values() 

58 if p.package_type in resolved_package_types 

59 ] 

60 if len(possible_matches) == 1: 60 ↛ 63line 60 didn't jump to line 63 because the condition on line 60 was always true

61 return possible_matches[0] 

62 

63 if package_attribute is not None: 

64 raise ManifestParseException( 

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

66 " for this source package." 

67 ) 

68 

69 if not possible_matches: 

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

71 raise ManifestParseException( 

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

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

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

75 ) 

76 raise ManifestParseException( 

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

78 ) 

79 

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

81 raise ManifestParseException(msg) 

82 

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

84 return package_name in self._package_states 

85 

86 def binary_package_data( 

87 self, 

88 package_name: str, 

89 ) -> "PackageTransformationDefinition": 

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

91 self._error( 

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

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

94 " for a package in debian/control." 

95 ) 

96 return self._package_states[package_name] 

97 

98 @property 

99 def dpkg_architecture_variables(self) -> DpkgArchitectureBuildProcessValuesTable: 

100 raise NotImplementedError 

101 

102 @property 

103 def dpkg_arch_query_table(self) -> DpkgArchTable: 

104 raise NotImplementedError 

105 

106 @property 

107 def deb_options_and_profiles(self) -> DebBuildOptionsAndProfiles: 

108 raise NotImplementedError 

109 

110 @contextlib.contextmanager 

111 def binary_package_context( 

112 self, 

113 package_name: str, 

114 ) -> Iterator["PackageTransformationDefinition"]: 

115 raise NotImplementedError 

116 

117 @property 

118 def substitution(self) -> Substitution: 

119 raise NotImplementedError 

120 

121 @property 

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

123 raise NotImplementedError 

124 

125 @property 

126 def is_in_binary_package_state(self) -> bool: 

127 raise NotImplementedError 

128 

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

130 raise NotImplementedError 

131 

132 @property 

133 def debputy_integration_mode(self) -> DebputyIntegrationMode: 

134 raise NotImplementedError 

135 

136 def resolve_build_environment( 

137 self, name: Optional[str], attribute_path: AttributePath 

138 ) -> BuildEnvironmentDefinition: 

139 raise NotImplementedError