Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a utility function that determines whether a part has slices #637

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
22 changes: 18 additions & 4 deletions craft_parts/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ def validate_root(cls, values: Dict[str, Any]) -> Dict[str, Any]:
# This check is only relevant in deb systems.
return values

def is_slice(name: str) -> bool:
return "_" in name

# Detect a mixture of .deb packages and chisel slices.
stage_packages = values.get("stage-packages", [])
has_slices = any(name for name in stage_packages if is_slice(name))
has_slices = part_has_slices(values)
has_packages = any(name for name in stage_packages if not is_slice(name))

if has_slices and has_packages:
Expand Down Expand Up @@ -642,6 +639,23 @@ def part_has_overlay(data: Dict[str, Any]) -> bool:
return spec.has_overlay


def part_has_slices(data: Dict[str, Any]) -> bool:
linostar marked this conversation as resolved.
Show resolved Hide resolved
"""Whether the part described by ``data`` has slices in its stage-packages.
linostar marked this conversation as resolved.
Show resolved Hide resolved

:param data: The part data to query.
"""
stage_packages = data.get("stage-packages", [])
return any(name for name in stage_packages if is_slice(name))


def is_slice(name: str) -> bool:
"""Whether the stage-package is a slice or a package.

:param name: name of the package.
"""
return "_" in name


def _get_part_spec(data: Dict[str, Any]) -> PartSpec:
if not isinstance(data, dict):
raise TypeError("value must be a dictionary")
Expand Down
Loading