craft_parts.sources.base module¶
Base classes for source type handling.
- class craft_parts.sources.base.BaseFileSourceModel(**data)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
Download the URL from a remote location.
- Parameters:
filepath (
Path|None) – the destination file to download to.- Return type:
Path
- class craft_parts.sources.base.SourceHandler(source, part_src_dir, *, cache_dir, project_dirs, ignore_patterns=None, **kwargs)[source]¶
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)[source]¶
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()[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.
- get_pull_snaps()[source]¶
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¶
-
source_details:
dict[str,str|None] |None¶
-
source_model:
ClassVar[type[BaseSourceModel]]¶
- update()[source]¶
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)[source]¶
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