craft_parts.sources.base module¶
Base classes for source type handling.
- class craft_parts.sources.base.BaseFileSourceModel(**data)[source]¶
Bases:
BaseSourceModel
A base model for file-based source types.
- 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] = {'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].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1), 'source_checksum': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='source-checksum', alias_priority=1), 'source_type': FieldInfo(annotation=str, required=True, alias='source-type', alias_priority=1)}¶
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.
-
source_checksum:
str
|None
¶
- class craft_parts.sources.base.BaseSourceModel(**data)[source]¶
Bases:
BaseModel
A base model for source types.
- 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] = {'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].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1), 'source_type': FieldInfo(annotation=str, required=True, alias='source-type', alias_priority=1)}¶
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.
-
source:
str
¶
-
source_type:
str
¶
- 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:
SourceHandler
Base class for file source types.
- 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
)
- download(filepath=None)[source]¶
Download the URL from a remote location.
- Parameters:
filepath (
Optional
[Path
]) – 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:
ABC
The 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 (
Optional
[list
[str
]])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.
- 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.
-
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