Coverage for src/debputy/manifest_parser/parser_data.py: 81%
59 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-10-12 15:06 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-10-12 15:06 +0000
1import contextlib
2from typing import (
3 Optional,
4 NoReturn,
5 TYPE_CHECKING,
6)
7from collections.abc import Iterator, Mapping
9from debian.debian_support import DpkgArchTable
11from debputy._deb_options_profiles import DebBuildOptionsAndProfiles
12from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable
13from debputy.manifest_parser.base_types import BuildEnvironmentDefinition
14from debputy.manifest_parser.exceptions import ManifestParseException
15from debputy.manifest_parser.util import AttributePath
16from debputy.manifest_parser.util import (
17 _ALL_PACKAGE_TYPES,
18 resolve_package_type_selectors,
19)
20from debputy.packages import BinaryPackage
21from debputy.plugin.api.impl_types import (
22 TP,
23 DispatchingTableParser,
24 TTP,
25)
26from debputy.plugin.api.spec import PackageTypeSelector, DebputyIntegrationMode
27from debputy.substitution import Substitution
29if TYPE_CHECKING:
30 from debputy.highlevel_manifest import PackageTransformationDefinition
33class ParserContextData:
34 @property
35 def binary_packages(self) -> Mapping[str, BinaryPackage]:
36 raise NotImplementedError
38 @property
39 def _package_states(self) -> Mapping[str, "PackageTransformationDefinition"]:
40 raise NotImplementedError
42 @property
43 def is_single_binary_package(self) -> bool:
44 return len(self.binary_packages) == 1
46 def single_binary_package(
47 self,
48 attribute_path: AttributePath,
49 *,
50 package_type: PackageTypeSelector = _ALL_PACKAGE_TYPES,
51 package_attribute: str | None = None,
52 ) -> BinaryPackage | None:
53 resolved_package_types = resolve_package_type_selectors(package_type)
54 possible_matches = [
55 p
56 for p in self.binary_packages.values()
57 if p.package_type in resolved_package_types
58 ]
59 if len(possible_matches) == 1: 59 ↛ 62line 59 didn't jump to line 62 because the condition on line 59 was always true
60 return possible_matches[0]
62 if package_attribute is not None:
63 raise ManifestParseException(
64 f"The {attribute_path.path} rule needs the attribute `{package_attribute}`"
65 " for this source package."
66 )
68 if not possible_matches:
69 _package_types = ", ".join(sorted(resolved_package_types))
70 raise ManifestParseException(
71 f"The {attribute_path.path} rule is not applicable to this source package"
72 f" (it only applies to source packages that builds exactly one of"
73 f" the following package types: {_package_types})."
74 )
75 raise ManifestParseException(
76 f"The {attribute_path.path} rule is not applicable to multi-binary packages."
77 )
79 def _error(self, msg: str) -> "NoReturn":
80 raise ManifestParseException(msg)
82 def is_known_package(self, package_name: str) -> bool:
83 return package_name in self._package_states
85 def binary_package_data(
86 self,
87 package_name: str,
88 ) -> "PackageTransformationDefinition":
89 if package_name not in self._package_states: 89 ↛ 90line 89 didn't jump to line 90 because the condition on line 89 was never true
90 self._error(
91 f'The package "{package_name}" is not present in the debian/control file (could not find'
92 f' "Package: {package_name}" in a binary stanza) nor is it a -dbgsym package for one'
93 " for a package in debian/control."
94 )
95 return self._package_states[package_name]
97 @property
98 def dpkg_architecture_variables(self) -> DpkgArchitectureBuildProcessValuesTable:
99 raise NotImplementedError
101 @property
102 def dpkg_arch_query_table(self) -> DpkgArchTable:
103 raise NotImplementedError
105 @property
106 def deb_options_and_profiles(self) -> DebBuildOptionsAndProfiles:
107 raise NotImplementedError
109 @contextlib.contextmanager
110 def binary_package_context(
111 self,
112 package_name: str,
113 ) -> Iterator["PackageTransformationDefinition"]:
114 raise NotImplementedError
116 @property
117 def substitution(self) -> Substitution:
118 raise NotImplementedError
120 @property
121 def current_binary_package_state(self) -> "PackageTransformationDefinition":
122 raise NotImplementedError
124 @property
125 def is_in_binary_package_state(self) -> bool:
126 raise NotImplementedError
128 def dispatch_parser_table_for(self, rule_type: TTP) -> DispatchingTableParser[TP]:
129 raise NotImplementedError
131 @property
132 def debputy_integration_mode(self) -> DebputyIntegrationMode:
133 raise NotImplementedError
135 def resolve_build_environment(
136 self, name: str | None, attribute_path: AttributePath
137 ) -> BuildEnvironmentDefinition:
138 raise NotImplementedError