Quellcode durchsuchen

refactor: dont create group/endgroup in INTERACTIVE mode, allow alternate messages

Sam Jaffe vor 1 Monat
Ursprung
Commit
2058ab2ea5
3 geänderte Dateien mit 25 neuen und 5 gelöschten Zeilen
  1. 5 2
      src/cipy/action.py
  2. 15 3
      src/cipy/runner.py
  3. 5 0
      src/cipy/settings.py

+ 5 - 2
src/cipy/action.py

@@ -11,6 +11,7 @@ from colored import Fore, Style
 from pydantic import Field, PrivateAttr
 
 import cipy.runner
+from cipy import settings
 from cipy.common import Action, Context, Factory, Ref, Results, Status, _validate
 from cipy.shell import Shell
 
@@ -116,12 +117,14 @@ class Script(Action):
         self.script = dedent(self.script).strip("\n")
         self._lines = self.script.splitlines()
         if not self.name:
-            self.name = self.shell.value + " script"
+            self.name = f"a {self.shell} script"
 
     @final
     @cipy.runner.ipc
     def run(self, context: Context) -> Status:
-        with cipy.runner.logging_group(self, self._lines[0]):
+        with cipy.runner.logging_group(self, self._lines[0], ci_only=True):
+            if settings.INTERACTIVE:
+                self.logger.warning("Run %s", self.name)
             for line in self._lines:
                 self.logger.info("%s%s%s", Script._GREEN, line, Style.reset)
             self.logger.info("shell: %s", " ".join(self.shell.command("{0}")))

+ 15 - 3
src/cipy/runner.py

@@ -12,6 +12,7 @@ from typing import Any, Callable, Iterator, TypeVar
 from dotenv import dotenv_values
 
 import cipy.common
+from cipy import settings
 from cipy.common import Context, Status, _validate
 
 Action = TypeVar("Action", bound=cipy.common.Action)
@@ -75,14 +76,25 @@ def ipc(func: Run[Action]) -> Run[Action]:
 
 
 @contextmanager
-def logging_group(self: Action, message: str, *args: Any) -> Iterator[None]:
+def logging_group(self: Action, msg: str, *args: Any,
+                  ci_only: bool = False) -> Iterator[None]:
     """
     Create a 'group' for logging messages under, allows for a GUI to apply cleaner formatting
+
+    :param Action self: The calling action
+    :param str msg: A message with optional formatting marks, see logging.Logger.log
+    :param Any *args: Any number of positional arguments for message formatting
+    :param bool ci_only: Should we only log anything in CI mode, or should we also
+        log with a slightly different format in INTERACTIVE (CLI) mode.
     """
 
-    self.logger.info("##[group] " + message, *args)
+    if not settings.INTERACTIVE:
+        self.logger.info("##[group] " + msg, *args)
+    elif not ci_only:
+        self.logger.warning(msg, *args)
     yield
-    self.logger.info("##[endgroup]")
+    if not settings.INTERACTIVE:
+        self.logger.info("##[endgroup]")
 
 
 def preamble(func: Run[Action]):

+ 5 - 0
src/cipy/settings.py

@@ -0,0 +1,5 @@
+"""Runtime/Buildtime Settings"""
+
+from typing import Final
+
+INTERACTIVE: Final[bool] = True