Coverage for src/debputy/plugin/api/plugin_parser.py: 100%
35 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-07 12:14 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-07 12:14 +0200
1from typing import NotRequired, List, Any, TypedDict
3from debputy.manifest_parser.base_types import (
4 DebputyParsedContent,
5 OctalMode,
6 TypeMapping,
7)
8from debputy.manifest_parser.declarative_parser import ParserGenerator
9from debputy.plugin.api.impl_types import KnownPackagingFileInfo
12class PPFReferenceDocumentation(TypedDict):
13 description: NotRequired[str]
14 format_documentation_uris: NotRequired[List[str]]
17class PackagerProvidedFileJsonDescription(DebputyParsedContent):
18 stem: str
19 installed_path: str
20 default_mode: NotRequired[OctalMode]
21 default_priority: NotRequired[int]
22 allow_name_segment: NotRequired[bool]
23 allow_architecture_segment: NotRequired[bool]
24 reference_documentation: NotRequired[PPFReferenceDocumentation]
27class ManifestVariableJsonDescription(DebputyParsedContent):
28 name: str
29 value: str
30 reference_documentation: NotRequired[str]
33class PluginJsonMetadata(DebputyParsedContent):
34 api_compat_version: int
35 module: NotRequired[str]
36 plugin_initializer: NotRequired[str]
37 packager_provided_files: NotRequired[List[Any]]
38 manifest_variables: NotRequired[List[Any]]
39 known_packaging_files: NotRequired[List[Any]]
42def _initialize_plugin_metadata_parser_generator() -> ParserGenerator:
43 pc = ParserGenerator()
44 pc.register_mapped_type(
45 TypeMapping(
46 OctalMode,
47 str,
48 lambda v, ap, _: OctalMode.parse_filesystem_mode(v, ap),
49 )
50 )
51 return pc
54PLUGIN_METADATA_PARSER_GENERATOR = _initialize_plugin_metadata_parser_generator()
55PLUGIN_METADATA_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.generate_parser(
56 PluginJsonMetadata
57)
58PLUGIN_PPF_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.generate_parser(
59 PackagerProvidedFileJsonDescription
60)
61PLUGIN_MANIFEST_VARS_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.generate_parser(
62 ManifestVariableJsonDescription
63)
64PLUGIN_KNOWN_PACKAGING_FILES_PARSER = PLUGIN_METADATA_PARSER_GENERATOR.generate_parser(
65 KnownPackagingFileInfo
66)