craft_parts.sources.snap_source module

The snap source handler.

class craft_parts.sources.snap_source.SnapSource(source, part_src_dir, *, cache_dir, project_dirs, source_checksum=None, command=None, ignore_patterns=None, **kwargs)[source]

Bases: FileSourceHandler

Handles downloading and extractions for a snap source.

On provision, the meta directory is renamed to meta.<snap-name> and, if present, the same applies for the snap directory which shall be renamed to snap.<snap-name>.

Parameters:
  • source (str)

  • part_src_dir (Path)

  • cache_dir (Path)

  • project_dirs (ProjectDirs)

  • source_checksum (Optional[str])

  • command (Optional[str])

  • ignore_patterns (Optional[list[str]])

  • kwargs (Any)

provision(dst, keep=False, src=None)[source]

Provision the snap source.

Parameters:
  • dst (Path) – The destination directory to provision to.

  • keep (bool) – Whether to keep the snap after provisioning is complete.

  • src (Optional[Path]) – Force a new source to use for extraction.

Return type:

None

raises errors.InvalidSnap: If trying to provision an invalid snap.

source_model

alias of SnapSourceModel

class craft_parts.sources.snap_source.SnapSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for a snap file source.

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'alias_generator': <function get_model_config.<locals>.<lambda>>, 'extra': 'forbid', 'frozen': True, 'json_schema_extra': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.snap$'}}}}}

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

pattern: ClassVar[str | None] = '\\.snap$'

A regular expression for inferring this source type.

If pattern is None (the default), the source type cannot be inferred and must always be explicitly written in the source-type field of a part.

source: str
source_checksum: str | None
source_type: Literal['snap']

The name of this source type.

Sources must define this with a type hint of a Literal type of its name and a value of its name.