From bdd8708abc91d48b79fce9be7639c481d9e04771 Mon Sep 17 00:00:00 2001 From: Anas Husseini Date: Thu, 28 Nov 2024 16:13:09 +0200 Subject: [PATCH] feat: add util functions part_has_slices and part_has_chisel_as_build_snap --- craft_parts/__init__.py | 10 +++++++++- craft_parts/parts.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/craft_parts/__init__.py b/craft_parts/__init__.py index cd402e27..3f52026c 100644 --- a/craft_parts/__init__.py +++ b/craft_parts/__init__.py @@ -26,7 +26,13 @@ from .features import Features from .infos import PartInfo, ProjectInfo, StepInfo from .lifecycle_manager import LifecycleManager -from .parts import Part, part_has_overlay, validate_part +from .parts import ( + Part, + part_has_chisel_as_build_snap, + part_has_slices, + part_has_overlay, + validate_part, +) from .steps import Step __all__ = [ @@ -46,4 +52,6 @@ "expand_environment", "validate_part", "part_has_overlay", + "part_has_slices", + "part_has_chisel_as_build_snap", ] diff --git a/craft_parts/parts.py b/craft_parts/parts.py index 7c689bf4..87725b81 100644 --- a/craft_parts/parts.py +++ b/craft_parts/parts.py @@ -684,6 +684,26 @@ def part_has_overlay(data: dict[str, Any]) -> bool: return spec.has_overlay +def part_has_slices(data: dict[str, Any]) -> bool: + """Whether the part described by ``data`` contains slices. + + :param data: The part data to query. + """ + spec = _get_part_spec(data) + + return spec.has_slices + + +def part_has_chisel_as_build_snap(data: dict[str, Any]) -> bool: + """Whether the part described by ``data`` has chisel in build-snaps. + + :param data: The part data to query. + """ + spec = _get_part_spec(data) + + return spec.has_chisel_as_build_snap + + def _get_part_spec(data: dict[str, Any]) -> PartSpec: if not isinstance(data, dict): raise TypeError("value must be a dictionary")