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 funcs part_has_slices and part_has_chisel_as_build_snap #914

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion craft_parts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand All @@ -46,4 +52,6 @@
"expand_environment",
"validate_part",
"part_has_overlay",
"part_has_slices",
"part_has_chisel_as_build_snap",
]
20 changes: 20 additions & 0 deletions craft_parts/parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down