craft_parts.parts module¶
Definitions and helpers to handle parts.
- class craft_parts.parts.Part(name, data, *, project_dirs=None, plugin_properties=None, partitions=None)[source]¶
Bases:
object
Each of the components used in the project specification.
During the craft-parts lifecycle each part is processed through different steps in order to obtain its final artifacts. The Part class holds the part specification data and additional configuration information used during step processing.
- Parameters:
name (
str
) – The part name.data (
Dict
[str
,Any
]) – A dictionary containing the part properties.partitions (
Optional
[Sequence
[str
]]) – A Sequence of partition names if partitions are enabled, or Noneproject_dirs (
Optional
[ProjectDirs
]) – The project work directories.plugin_properties (
Optional
[PluginProperties
]) – An optional PluginProperties object for this plugin.
- Raises:
PartSpecificationError – If part validation fails.
- property base_prime_dir: Path¶
Return the primed tree containing the artifacts to deploy.
If partitions are enabled, this is the directory containing those partitions.
- Return type:
Path
- property base_stage_dir: Path¶
Return the base staging area.
If partitions are enabled, this is the directory containing those partitions.
- Return type:
Path
- check_partition_usage(partitions)[source]¶
Check if partitions are properly used in a part.
- Parameters:
partitions (
List
[str
]) – The list of valid partitions.- Return type:
List
[str
]- Returns:
A list of invalid uses of partitions in the part.
- property dependencies: List[str]¶
Return the list of parts this part depends on.
- Return type:
List
[str
]
- property has_overlay: bool¶
Return whether this part declares overlay content.
- Return type:
bool
- property overlay_dir: Path¶
Return the overlay directory.
- Return type:
Path
- property part_base_install_dir: Path¶
The base of the part’s install directories.
With partitions disabled, this is the install directory. With partitions enabled, this is the directory containing the partitions.
A full path to an install location can always be found with:
part.part_base_install_dir / get_partition_compatible_filepath(location)
- Return type:
Path
- property part_build_dir: Path¶
Return the subdirectory containing the part build tree.
- Return type:
Path
- property part_build_subdir: Path¶
Return the subdirectory in build containing the source subtree (if any).
Parts that have a source subdirectory and do not support out-of-source builds will have a build subdirectory.
- Return type:
Path
- property part_cache_dir: Path¶
Return the subdirectory containing the part cache directory.
- Return type:
Path
- property part_install_dir: Path¶
Return the subdirectory to install the part build artifacts.
With partitions disabled, this is the install directory and is the same as
part_base_install_dir
With partitions enabled, this is the install directory for the default partition- Return type:
Path
- property part_install_dirs: Mapping[Optional[str], Path]¶
Return a mapping of partition names to install directories.
With partitions disabled, the only partition name is
None
- Return type:
Mapping
[Optional
[str
],Path
]
- property part_layer_dir: Path¶
Return the subdirectory containing the part overlay files.
- Return type:
Path
- property part_packages_dir: Path¶
Return the subdirectory containing the part stage packages directory.
- Return type:
Path
- property part_run_dir: Path¶
Return the subdirectory containing the part plugin scripts.
- Return type:
Path
- property part_snaps_dir: Path¶
Return the subdirectory containing the part snap packages directory.
- Return type:
Path
- property part_src_dir: Path¶
Return the subdirectory containing the part source code.
- Return type:
Path
- property part_src_subdir: Path¶
Return the subdirectory in source containing the source subtree (if any).
- Return type:
Path
- property part_state_dir: Path¶
Return the subdirectory containing the part lifecycle state.
- Return type:
Path
- property parts_dir: Path¶
Return the directory containing work files for each part.
- Return type:
Path
- property prime_dir: Path¶
Return the primed tree containing the artifacts to deploy.
If partitions are enabled, this is the prime directory for the default partition
- Return type:
Path
- property prime_dirs: Mapping[Optional[str], Path]¶
A mapping of partition name to partition prime directory.
If partitions are disabled, the only key is
None
.- Return type:
Mapping
[Optional
[str
],Path
]
- property stage_dir: Path¶
Return the staging area containing the installed files from all parts.
If partitions are enabled, this is the stage directory for the default partition
- Return type:
Path
- property stage_dirs: Mapping[Optional[str], Path]¶
A mapping of partition name to partition staging directory.
If partitions are disabled, the only key is
None
.- Return type:
Mapping
[Optional
[str
],Path
]
- class craft_parts.parts.PartSpec(**data)[source]¶
Bases:
BaseModel
The part specification data.
- Parameters:
data (
Any
) –
- class Config[source]¶
Bases:
object
Pydantic model configuration.
- alias_generator()¶
- allow_mutation = False¶
- extra = 'forbid'¶
- validate_assignment = True¶
- after: List[str]¶
- build_attributes: List[str]¶
- build_environment: List[Dict[str, str]]¶
- build_packages: List[str]¶
- build_snaps: List[str]¶
- disable_parallel: bool¶
- get_scriptlet(step)[source]¶
Return the scriptlet contents, if any, for the given step.
- Parameters:
step (
Step
) – the step corresponding to the scriptlet to be retrieved.- Return type:
Optional
[str
]- Returns:
The scriptlet for the given step, if any.
- property has_overlay: bool¶
Return whether this spec declares overlay content.
- Return type:
bool
- marshal()[source]¶
Create a dictionary containing the part specification data.
- Return type:
Dict
[str
,Any
]- Returns:
The newly created dictionary.
- organize_files: Dict[str, str]¶
- overlay_files: List[str]¶
- overlay_packages: List[str]¶
- overlay_script: Optional[str]¶
- override_build: Optional[str]¶
- override_prime: Optional[str]¶
- override_pull: Optional[str]¶
- override_stage: Optional[str]¶
- permissions: List[Permissions]¶
- plugin: Optional[str]¶
- prime_files: List[str]¶
- source: Optional[str]¶
- source_branch: str¶
- source_checksum: str¶
- source_commit: str¶
- source_depth: int¶
- source_subdir: str¶
- source_submodules: Optional[List[str]]¶
- source_tag: str¶
- source_type: str¶
- stage_files: List[str]¶
- stage_packages: List[str]¶
- stage_snaps: List[str]¶
- classmethod unmarshal(data)[source]¶
Create and populate a new
PartSpec
object from dictionary data.The unmarshal method validates entries in the input dictionary, populating the corresponding fields in the data object.
- Parameters:
data (
Dict
[str
,Any
]) – The dictionary data to unmarshal.- Return type:
- Returns:
The newly created object.
- Raises:
TypeError – If data is not a dictionary.
- classmethod validate_overlay_feature(item)[source]¶
Check if overlay attributes specified when feature is disabled.
- Parameters:
item (
Any
) –- Return type:
Any
- craft_parts.parts.get_parts_with_overlay(*, part_list)[source]¶
Obtain a list of parts that declare overlay parameters.
- craft_parts.parts.has_overlay_visibility(part, *, part_list, viewers=None)[source]¶
Check if a part can see the overlay filesystem.
A part that declares overlay parameters and all parts depending on it are granted permission to see overlay filesystem.
- craft_parts.parts.part_by_name(name, part_list)[source]¶
Obtain the part with the given name from the part list.
- craft_parts.parts.part_dependencies(part, *, part_list, recursive=False)[source]¶
Return a set of all the parts upon which the named part depends.
- craft_parts.parts.part_has_overlay(data)[source]¶
Whether the part described by
data
employs the Overlay step.- Parameters:
data (
Dict
[str
,Any
]) – The part data to query for overlay use.- Return type:
bool
- craft_parts.parts.part_list_by_name(names, part_list)[source]¶
Return a list of parts from part_list that are named in names.
- Parameters:
names (
Optional
[Sequence
[str
]]) – The list of part names. If the list is empty or not defined, return all parts from part_list.part_list (
List
[Part
]) – The list of all known parts.
- Return type:
List
[Part
]- Returns:
The list of parts corresponding to the given names.
- Raises:
InvalidPartName – if a part name is not defined.
- craft_parts.parts.sort_parts(part_list)[source]¶
Perform an inefficient but easy to follow sorting of parts.
- Parameters:
part_list (
List
[Part
]) – The list of parts to sort.- Return type:
List
[Part
]- Returns:
The sorted list of parts.
- Raises:
PartDependencyCycle – if there are circular dependencies.
- craft_parts.parts.validate_part(data)[source]¶
Validate the given part data against common and plugin models.
- Parameters:
data (
Dict
[str
,Any
]) – The part data to validate.- Return type:
None
- craft_parts.parts.validate_partition_usage(part_list, partitions)[source]¶
Validate usage of partitions in a list of parts.
For each part, the use of partitions in filepaths in overlay, stage, prime, and organize keywords are validated.
- Parameters:
part_list (
List
[Part
]) – The list of parts to validate.partitions (
List
[str
]) – The list of valid partitions.
- Raises:
ValueError – If partitions are not used properly in the list of parts.
- Return type:
None