|
@@ -17,7 +17,6 @@ from cipy.common import Context, Status, _validate
|
|
|
|
|
|
|
|
Action = TypeVar("Action", bound=cipy.common.Action)
|
|
Action = TypeVar("Action", bound=cipy.common.Action)
|
|
|
type Run[Action] = Callable[[Action, Context], Status]
|
|
type Run[Action] = Callable[[Action, Context], Status]
|
|
|
-type GetLines[Action] = Callable[[Action], str | Iterable[str]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
@contextmanager
|
|
@@ -83,31 +82,12 @@ def logging_group(self: Action, message: str, *args: Any) -> Iterator[None]:
|
|
|
self.logger.info("##[endgroup]")
|
|
self.logger.info("##[endgroup]")
|
|
|
|
|
|
|
|
|
|
|
|
|
-@overload
|
|
|
|
|
-def preamble(
|
|
|
|
|
- func: Run[Action], *extra: tuple[str, GetLines[Action]]
|
|
|
|
|
-) -> Run[Action]: ...
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-@overload
|
|
|
|
|
-def preamble(
|
|
|
|
|
- func: tuple[str, GetLines[Action]], *extra: tuple[str, GetLines[Action]]
|
|
|
|
|
-) -> Callable[[Run[Action]], Run[Action]]: ...
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def preamble(
|
|
|
|
|
- func: Run[Action] | tuple[str, GetLines[Action]],
|
|
|
|
|
- *extra: tuple[str, GetLines[Action]],
|
|
|
|
|
-):
|
|
|
|
|
- if isinstance(func, tuple):
|
|
|
|
|
- return lambda f: preamble(f, func, *extra)
|
|
|
|
|
|
|
+def preamble(func: Run[Action]):
|
|
|
|
|
|
|
|
@functools.wraps(func)
|
|
@functools.wraps(func)
|
|
|
def wrapper(self: Action, context: Context) -> Status:
|
|
def wrapper(self: Action, context: Context) -> Status:
|
|
|
with logging_group(self, "Run %s", self.name):
|
|
with logging_group(self, "Run %s", self.name):
|
|
|
_log_inputs(self)
|
|
_log_inputs(self)
|
|
|
- for color, get_lines in extra:
|
|
|
|
|
- _log_extra(self, color, get_lines(self))
|
|
|
|
|
return func(self, context)
|
|
return func(self, context)
|
|
|
|
|
|
|
|
return wrapper
|
|
return wrapper
|
|
@@ -119,12 +99,3 @@ def _log_inputs(self: Action) -> None:
|
|
|
self.logger.info("with:")
|
|
self.logger.info("with:")
|
|
|
for key, value in inputs:
|
|
for key, value in inputs:
|
|
|
self.logger.info(" %s: %s", key, value)
|
|
self.logger.info(" %s: %s", key, value)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def _log_extra(self: Action, color: str, lines: str | Iterable[str]) -> None:
|
|
|
|
|
- fmt = f"{color}%s{Style.reset}"
|
|
|
|
|
- if isinstance(lines, str):
|
|
|
|
|
- self.logger.info(fmt, lines)
|
|
|
|
|
- else:
|
|
|
|
|
- for line in lines:
|
|
|
|
|
- self.logger.info(fmt, line)
|
|
|