craft_parts.sources package¶
Submodules¶
- craft_parts.sources.base module
- craft_parts.sources.cache module
- craft_parts.sources.checksum module
- craft_parts.sources.deb_source module
- craft_parts.sources.errors module
- craft_parts.sources.file_source module
- craft_parts.sources.git_source module
- craft_parts.sources.local_source module
- craft_parts.sources.rpm_source module
- craft_parts.sources.sevenzip_source module
- craft_parts.sources.snap_source module
- craft_parts.sources.sources module
- craft_parts.sources.tar_source module
- craft_parts.sources.zip_source module
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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.deb$'}}}}}¶
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=Literal['deb'], required=False, default='deb', 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_type:
Literal
['deb'
]¶
- 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_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=Literal['file'], 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_type:
Literal
['file'
]¶
- 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
, andsource-submodules
.- Parameters:
source (
str
)part_src_dir (
Path
)kwargs (
Any
)
-
command:
ClassVar
[str
] = 'git'¶
- 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
- source_model¶
alias of
GitSourceModel
- class craft_parts.sources.GitSourceModel(**data)[source]¶
Bases:
BaseSourceModel
Pydantic model for a git-based source.
- 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': {'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].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1), 'source_branch': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='source-branch', alias_priority=1), 'source_commit': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='source-commit', alias_priority=1), 'source_depth': FieldInfo(annotation=int, required=False, default=0, alias='source-depth', alias_priority=1), 'source_submodules': FieldInfo(annotation=Union[list[str], NoneType], required=False, default=None, alias='source-submodules', alias_priority=1), 'source_tag': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='source-tag', alias_priority=1), 'source_type': FieldInfo(annotation=Literal['git'], required=False, default='git', 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_branch:
str
|None
¶
-
source_commit:
str
|None
¶
-
source_depth:
int
¶
-
source_submodules:
list
[str
] |None
¶
-
source_tag:
str
|None
¶
-
source_type:
Literal
['git'
]¶
- 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.
- 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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '^\\./?'}}}}}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'source': FieldInfo(annotation=Path, required=True, alias='source', alias_priority=1, metadata=[AfterValidator(func=<function LocalSourceModel.<lambda>>)]), 'source_type': FieldInfo(annotation=Literal['local'], required=False, default='local', 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:
Annotated
[Path
]¶
-
source_type:
Literal
['local'
]¶
- 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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.rpm$'}}}}}¶
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=Literal['rpm'], required=False, default='rpm', 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_type:
Literal
['rpm'
]¶
- 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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.7z$'}}}}}¶
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=Literal['7z'], required=False, default='7z', 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_type:
Literal
['7z'
]¶
- 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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.snap$'}}}}}¶
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=Literal['snap'], required=False, default='snap', 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_type:
Literal
['snap'
]¶
- 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_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': {'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].
- 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=Literal['tar'], required=False, default='tar', 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_type:
Literal
['tar'
]¶
- 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_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': {'if': {'not': {'required': ['source-type']}}, 'then': {'properties': {'source': {'pattern': '\\.zip$'}}}}}¶
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=Literal['zip'], required=False, default='zip', 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_type:
Literal
['zip'
]¶