Jelajahi Sumber

refactor: simple logging

Sam Jaffe 1 bulan lalu
induk
melakukan
bad2c527a9
3 mengubah file dengan 16 tambahan dan 0 penghapusan
  1. 1 0
      src/cipy/action.py
  2. 13 0
      src/cipy/common.py
  3. 2 0
      src/cipy/workflow.py

+ 1 - 0
src/cipy/action.py

@@ -51,6 +51,7 @@ class Script(Action):
     @final
     @cipy.runner.ipc
     def run(self, context: Context) -> Status:
+        self.log(f"Running {self.shell} script:\n{self.script}")
         with tempfile.TemporaryFile(mode="w+", suffix=self.shell.extension()) as script:
             script.write(self.script)
             try:

+ 13 - 0
src/cipy/common.py

@@ -2,6 +2,7 @@
 
 import abc
 import dataclasses
+import logging
 import os
 
 from contextlib import contextmanager
@@ -139,6 +140,18 @@ class Action(BaseModel, abc.ABC):
     inputs: Inputs = Inputs()
     outputs: Outputs = Outputs()
 
+    @classmethod
+    def log(
+        cls,
+        message: str,
+        *args: Any,
+        indent: int = 0,
+        level: int = logging.INFO,
+        **kwargs: Any,
+    ) -> None:
+        logger = logging.getLogger(cls.__name__)
+        logger.log(level, ("  " * indent) + message, *args, **kwargs)
+
     # pylint: disable=unused-argument
     def enabled(self, status: Status, context: Context) -> bool:
         """Should this action even be run?"""

+ 2 - 0
src/cipy/workflow.py

@@ -51,6 +51,7 @@ class Workflow(Action):
 
         with context.extend(needs=Results()) as outctx:
             while job := _next():
+                self.log(f"Running Job: {job.id}")
                 visited.add(job.id)
 
                 if job.action.enabled(status, context):
@@ -99,6 +100,7 @@ class Matrix(Action):
         status = Status.SUCCESS
 
         for matrix in self._expand(context):
+            self.log(str(matrix))
             with context.extend(matrix=matrix) as matctx:
                 tmp = copy.deepcopy(self.uses)
                 status |= tmp.run(matctx)