feat(tools): Add 'check' field to idf.py actions

This commit is contained in:
Tomas Rezucha
2026-07-16 12:16:11 +08:00
committed by BOT
parent f7e24571ea
commit 32e1303c3e
4 changed files with 41 additions and 18 deletions
+16
View File
@@ -255,6 +255,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
def __init__(
self,
callback: Callable,
check: Callable | None,
name: str,
aliases: list,
dependencies: list | None,
@@ -262,6 +263,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
action_args: dict,
) -> None:
self.callback = callback
self.check = check
self.name = name
self.dependencies = dependencies
self.order_dependencies = order_dependencies
@@ -274,6 +276,15 @@ def init_cli(verbose_output: list | None = None) -> Any:
self.callback(self.name, context, global_args, **action_args)
def check_requirements(
self, context: click.core.Context, global_args: PropertyDict, action_args: dict | None = None
) -> bool:
if self.check is None:
return True
if action_args is None:
action_args = self.action_args
return bool(self.check(self.name, context, global_args, **action_args))
class Action(click.RichCommand):
callback: Callable
@@ -284,6 +295,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
deprecated: dict | str | bool = False,
dependencies: list | None = None,
order_dependencies: list | None = None,
check: Callable | None = None,
hidden: bool = False,
**kwargs: Any,
) -> None:
@@ -326,6 +338,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
def wrapped_callback(**action_args: Any) -> Task:
return Task(
callback=self.unwrapped_callback,
check=check,
name=self.name,
dependencies=dependencies,
order_dependencies=order_dependencies,
@@ -796,6 +809,9 @@ def init_cli(verbose_output: list | None = None) -> Any:
dependecies_processed = True
if not task.check_requirements(ctx, global_args, task.action_args):
raise FatalError(f'Action "{task.name}" cannot run in the current project configuration.')
# If task have some dependencies they have to be executed before the task.
for dep in task.dependencies:
if dep not in tasks_to_run.keys():