craft_parts.sources.base module¶
Base classes for source type handling.
- class craft_parts.sources.base.BaseFileSourceModel(**data)¶
Bases:
BaseSourceModelA base model for file-based source types.
- 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: str¶
-
source_checksum:
str|None¶
- source_type: str¶
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.base.BaseSourceModel(**data)¶
Bases:
BaseModelA base model for source types.
- 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].
-
pattern:
ClassVar[str|None] = None¶ 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_type:
str¶ 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.base.FileSourceHandler(source, part_src_dir, *, cache_dir, project_dirs, source_checksum=None, command=None, ignore_patterns=None, **kwargs)¶
Bases:
SourceHandlerBase class for file source types.
- Parameters:
source (
str)part_src_dir (
Path)cache_dir (
Path)project_dirs (
ProjectDirs)source_checksum (
str|None)command (
str|None)ignore_patterns (
list[str] |None)kwargs (
Any)
- download(filepath=None)¶
Download the URL from a remote location.
- Parameters:
filepath (
Path|None) – the destination file to download to.- Return type:
Path
- abstract provision(dst, keep=False, src=None)¶
Process the source file to extract its payload.
- Parameters:
dst (
Path)keep (
bool)src (
Path|None)
- Return type:
None
- pull()¶
Retrieve this source from its origin.
- Return type:
None
- class craft_parts.sources.base.SourceHandler(source, part_src_dir, *, cache_dir, project_dirs, ignore_patterns=None, **kwargs)¶
Bases:
ABCThe base class for source type handlers.
Methods
check_if_outdated()andupdate_source()can be overridden by subclasses to implement verification and update of source files.- Parameters:
source (
str)part_src_dir (
Path)cache_dir (
Path)project_dirs (
ProjectDirs)ignore_patterns (
list[str] |None)kwargs (
Any)
- check_if_outdated(target, *, ignore_files=None)¶
Check if pulled sources have changed since target was created.
- Parameters:
target (
str) – Path to target file.ignore_files (
list[str] |None) – Files excluded from verification.
- Return type:
bool- Returns:
Whether the sources are outdated.
- Raises:
errors.SourceUpdateUnsupported – If the source handler can’t check if files are outdated.
- get_outdated_files()¶
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.
- get_pull_snaps()¶
Return the set of snaps needed for handling this source type.
- Return type:
set[str]
-
outdated_dirs:
list[str] |None¶
-
outdated_files:
list[str] |None¶
- abstract pull()¶
Retrieve the source file.
- Return type:
None
-
source_details:
dict[str,str|None] |None¶
-
source_model:
ClassVar[type[BaseSourceModel]]¶
- update()¶
Update pulled source.
- Raises:
errors.SourceUpdateUnsupported – If the source can’t update its files.
- Return type:
None
- craft_parts.sources.base.get_json_extra_schema(type_pattern)¶
Get extra values for this source type’s JSON schema.
This extra schema allows any source string if source-type is provided, but requires the given regex pattern if source-type is not declared. A user’s IDE will thus warn that they need “source-type” only if the source type cannot be inferred.
- Parameters:
type_pattern (
str) – A (string) regular expression to use in determining whether the source string is sufficient to infer source-type.- Return type:
dict[str,dict[str,Any]]- Returns:
A dictionary to pass into a source model’s config
json_schema_extra
- craft_parts.sources.base.get_model_config(json_schema_extra=None)¶
Get a config for a model with minor changes from the default.
- Parameters:
json_schema_extra (
dict[str,Any] |None)- Return type:
ConfigDict