craft_parts.utils.path_utils module

Utility functions for paths.

class craft_parts.utils.path_utils.PartitionPathPair(partition: Optional[str], path: Union[PurePath, str])[source]

Bases: tuple

A pair containing a partition name and a path.

partition: Optional[str]

Alias for field number 0

path: Union[PurePath, str]

Alias for field number 1

craft_parts.utils.path_utils.get_partition_and_path(path)[source]

Break a partition path into the partition and the child path.

If the path begins with a partition, that is used. Otherwise, the default partition is used. If partitions are not enabled, the partition will be None.

Parameters:

path (TypeVar(FlexiblePath, PurePath, str)) – The filepath to parse.

Return type:

PartitionPathPair

Returns:

A tuple of (partition, filepath)

craft_parts.utils.path_utils.get_partitioned_path(path)[source]

Get a filepath compatible with the partitions feature.

If the filepath begins with a partition, then the parentheses are stripped from the the partition. For example, (default)/file is converted to default/file.

If the filepath does not begin with a partition, the default partition is prepended. For example, file is converted to default/file.

Parameters:

path (TypeVar(FlexiblePath, PurePath, str)) – The filepath to modify.

Return type:

TypeVar(FlexiblePath, PurePath, str)

Returns:

A filepath that is compatible with the partitions feature.