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