craft_parts.sources package

Submodules

Module contents

Source handler definitions and helpers.

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

Bases: FileSourceHandler

The “deb” file source handler.

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]

Extract deb file contents to the part source dir.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of DebSourceModel

class craft_parts.sources.DebSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for deb file sources.

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': '\\.deb$'}}}}}

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

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

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_type: Literal['deb']

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.

class craft_parts.sources.FileSource(source, part_src_dir, *, cache_dir, project_dirs, ignore_patterns=None, **kwargs)[source]

Bases: FileSourceHandler

The plain file source handler.

Parameters:
  • source (str)

  • part_src_dir (Path)

  • cache_dir (Path)

  • project_dirs (ProjectDirs)

  • ignore_patterns (Optional[list[str]])

  • kwargs (Any)

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

Process the source file to extract its payload.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of FileSourceModel

class craft_parts.sources.FileSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for plain file source.

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'alias_generator': <function get_model_config.<locals>.<lambda>>, 'extra': 'forbid', 'frozen': True, 'json_schema_extra': None}

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

source_type: Literal['file']

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.

class craft_parts.sources.GitSource(source, part_src_dir, **kwargs)[source]

Bases: SourceHandler

The git source handler.

Retrieve part sources from a git repository. Branch, depth, commit and tag can be specified using part properties source-branch, source-depth, source-commit`, source-tag, and source-submodules.

Parameters:
  • source (str)

  • part_src_dir (Path)

  • kwargs (Any)

classmethod check_command_installed()[source]

Check if git is installed.

Return type:

bool

classmethod generate_version(*, part_src_dir=None)[source]

Return the latest git tag from PWD or defined part_src_dir.

The output depends on the use of annotated tags and will return something like: ‘2.28+git.10.abcdef’ where ‘2.28 is the tag, ‘+git’ indicates there are commits ahead of the tag, in this case it is ‘10’ and the latest commit hash begins with ‘abcdef’. If there are no tags or the revision cannot be determined, this will return 0 as the tag and only the commit hash of the latest commit.

Parameters:

part_src_dir (Optional[Path])

Return type:

str

is_local()[source]

Verify whether the git repository is on the local filesystem.

Return type:

bool

pull()[source]

Retrieve the local or remote source files.

Return type:

None

source_model

alias of GitSourceModel

classmethod version()[source]

Get git version information.

Return type:

str

class craft_parts.sources.GitSourceModel(**data)[source]

Bases: BaseSourceModel

Pydantic model for a git-based 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': '(^git[+@:]|\\.git$)'}}}}}

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

pattern: ClassVar[str | None] = '(^git(\\+.+:|[@:])|\\.git$)'

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_branch: str | None
source_commit: str | None
source_depth: int
source_submodules: list[str] | None
source_tag: str | None
source_type: Literal['git']

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.

class craft_parts.sources.LocalSource(*args, project_dirs, copy_function=<function link_or_copy>, **kwargs)[source]

Bases: SourceHandler

The local source handler.

Parameters:
  • args (Any)

  • project_dirs (ProjectDirs)

  • copy_function (Callable[..., None])

  • kwargs (Any)

check_if_outdated(target, *, ignore_files=None)[source]

Check if pulled sources have changed since target was created.

Parameters:
  • target (str) – Path to target file.

  • ignore_files (Optional[list[str]]) – Files excluded from verification.

Return type:

bool

Returns:

Whether the sources are outdated.

get_outdated_files()[source]

Obtain lists of outdated files and directories.

Return type:

tuple[list[str], list[str]]

Returns:

The lists of outdated files and directories.

Raises:

errors.SourceUpdateUnsupported – If the source handler can’t check if files are outdated.

pull()[source]

Retrieve the local source files.

Return type:

None

source_model

alias of LocalSourceModel

update()[source]

Update pulled source.

Call method check_if_outdated() before updating to populate the lists of files and directories to copy.

Return type:

None

class craft_parts.sources.LocalSourceModel(**data)[source]

Bases: BaseSourceModel

Pydantic model for a generic local 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': '^\\./?'}}}}}

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

source: Annotated[Path]
source_type: Literal['local']

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.

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

Bases: FileSourceHandler

The “rpm” file source handler.

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]

Extract rpm file contents to the part source dir.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of RpmSourceModel

class craft_parts.sources.RpmSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for an rpm 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': '\\.rpm$'}}}}}

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

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

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_type: Literal['rpm']

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.

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

Bases: FileSourceHandler

The zip file source handler.

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]

Extract 7z file contents to the part source dir.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of SevenzipSourceModel

class craft_parts.sources.SevenzipSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic for a 7zip 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': '\\.7z$'}}}}}

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

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

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_type: Literal['7z']

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.

class craft_parts.sources.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.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_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.

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

Bases: FileSourceHandler

The tar source handler.

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]

Extract tarball contents to the part source dir.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of TarSourceModel

class craft_parts.sources.TarSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for a tar 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': '\\.(tar(\\.[a-z0-9]+)?|tgz)$'}}}}}

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

pattern: ClassVar[str | None] = '\\.(tar(\\.[a-z0-9]+)?|tgz)$'

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_type: Literal['tar']

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.

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

Bases: FileSourceHandler

The zip file source handler.

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]

Extract zip file contents to the part source dir.

Parameters:
  • dst (Path)

  • keep (bool)

  • src (Optional[Path])

Return type:

None

source_model

alias of ZipSourceModel

class craft_parts.sources.ZipSourceModel(**data)[source]

Bases: BaseFileSourceModel

Pydantic model for a zip 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': '\\.zip$'}}}}}

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

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

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_type: Literal['zip']

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.

craft_parts.sources.register(source, /)[source]

Register source handlers.

Parameters:

source (type[SourceHandler]) – a SourceHandler class to register.

Raises:

ValueError if the source handler overrides a built-in source type.

Return type:

None

craft_parts.sources.unregister(source, /)[source]

Unregister a source handler by name.

Parameters:

source (str)

Return type:

None