from __future__ import annotations import shutil from typing import TYPE_CHECKING from django.conf import settings from django.core.checks import Tags from django.core.checks import Warning as DjangoWarning from django.core.checks import register if TYPE_CHECKING: from django.core.checks import CheckMessage REQUIRED_DEV_COMMANDS: tuple[str, ...] = ( "uname", "curl", "basename", "grep", "sort", "tail", "wget", "unsquashfs", "ssh-keygen", "sudo", "chown", "truncate", "mkfs.ext4", "e2fsck", ) @register(Tags.compatibility) def check_required_dev_commands(*_: object, **__: object) -> list[CheckMessage]: """Warn in dev-like runtime when host tooling for init script is missing. Returns: A list of CheckMessage objects representing any issues found. """ if not (settings.DEBUG or getattr(settings, "TESTING", False)): return [] missing_commands: list[str] = [ command for command in REQUIRED_DEV_COMMANDS if shutil.which(command) is None ] if not missing_commands: return [] return [ DjangoWarning( "Missing host commands used by get_rootfs.bash.", hint=( "Dev-only tooling missing: " f"{', '.join(missing_commands)}. " "These are required for local VM/rootfs setup during development, not production runtime." ), id="tussilago.W001", ), ]