craft_parts.pydantic_schema module

Experiments with pydantic schemas.

class craft_parts.pydantic_schema.Part(**data)[source]

Bases: BaseModel

Generic schema for all parts.

Parameters:

data (Any)

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'plugin_data': FieldInfo(annotation=PluginProperties, required=True), 'source_data': FieldInfo(annotation=Union[DebSourceModel, FileSourceModel, GitSourceModel, LocalSourceModel, RpmSourceModel, SevenzipSourceModel, SnapSourceModel, TarSourceModel, ZipSourceModel], required=True, metadata=[BeforeValidator(func=<function _detect_source_type>, json_schema_input_type=PydanticUndefined), Discriminator(discriminator='source_type', custom_error_type=None, custom_error_message=None, custom_error_context=None)])}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')[source]

Create the JSON schema for a Part.

Parameters:
  • by_alias (bool)

  • ref_template (str)

  • schema_generator (type[GenerateJsonSchema])

  • mode (Literal['validation', 'serialization'])

Return type:

dict[str, Any]

plugin_data: PluginProperties
source_data: Annotated[DebSourceModel | FileSourceModel | GitSourceModel | LocalSourceModel | RpmSourceModel | SevenzipSourceModel | SnapSourceModel | TarSourceModel | ZipSourceModel]
class craft_parts.pydantic_schema.PartsFile(**data)[source]

Bases: BaseModel

A root model for a file that contains a ‘parts’ key.

Parameters:

data (Any)

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'parts': FieldInfo(annotation=dict[str, Any], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')[source]

Create the JSON schema for a file with Parts.

Parameters:
  • by_alias (bool)

  • ref_template (str)

  • schema_generator (type[GenerateJsonSchema])

  • mode (Literal['validation', 'serialization'])

Return type:

dict[str, Any]

parts: dict[str, Any]