Ver código fonte

refactor: move Status to a separate file

Sam Jaffe 4 semanas atrás
pai
commit
3ac04d5c60
6 arquivos alterados com 25 adições e 18 exclusões
  1. 2 1
      src/cipy/__init__.py
  2. 2 1
      src/cipy/action.py
  3. 2 14
      src/cipy/common.py
  4. 2 1
      src/cipy/runner.py
  5. 15 0
      src/cipy/status.py
  6. 2 1
      src/cipy/workflow.py

+ 2 - 1
src/cipy/__init__.py

@@ -10,8 +10,9 @@ import sys
 import pydantic
 import pydantic
 
 
 from cipy.action import Call, Composite, NodeScript, Script
 from cipy.action import Call, Composite, NodeScript, Script
-from cipy.common import Context, Factory, Inputs, Outputs, Ref, Status
+from cipy.common import Context, Factory, Inputs, Outputs, Ref
 from cipy.shell import Shell
 from cipy.shell import Shell
+from cipy.status import Status
 from cipy.workflow import Job, Matrix, MatrixParams, Workflow
 from cipy.workflow import Job, Matrix, MatrixParams, Workflow
 
 
 from . import settings
 from . import settings

+ 2 - 1
src/cipy/action.py

@@ -12,8 +12,9 @@ from pydantic import Field, PrivateAttr
 
 
 import cipy.runner
 import cipy.runner
 from cipy import settings
 from cipy import settings
-from cipy.common import Action, Context, Factory, Ref, Results, Status
+from cipy.common import Action, Context, Factory, Ref, Results
 from cipy.shell import Shell
 from cipy.shell import Shell
+from cipy.status import Status
 
 
 from . import _io
 from . import _io
 
 

+ 2 - 14
src/cipy/common.py

@@ -6,7 +6,6 @@ import logging
 import os
 import os
 
 
 from contextlib import contextmanager
 from contextlib import contextmanager
-from enum import Enum, auto
 from functools import reduce
 from functools import reduce
 from types import SimpleNamespace, NoneType
 from types import SimpleNamespace, NoneType
 from typing import Annotated, Any, Callable, Iterator, Literal, Self, final, overload
 from typing import Annotated, Any, Callable, Iterator, Literal, Self, final, overload
@@ -14,24 +13,13 @@ from typing import Annotated, Any, Callable, Iterator, Literal, Self, final, ove
 from pydantic import BaseModel, Field
 from pydantic import BaseModel, Field
 from pydantic_core import PydanticUndefined
 from pydantic_core import PydanticUndefined
 
 
+from cipy.status import Status
+
 type Scalar = bool | int | float | str
 type Scalar = bool | int | float | str
 type Computed = Ref | Factory
 type Computed = Ref | Factory
 type Value = Scalar | Computed
 type Value = Scalar | Computed
 
 
 
 
-class Status(Enum):
-    """Result status of a runner, higher numbers take priority"""
-
-    NOT_RUN = auto()
-    SKIPPED = auto()
-    SUCCESS = auto()
-    FAILURE = auto()
-    CANCELLED = auto()
-
-    def __ior__(self, other: Status) -> Status:
-        return self if self.value > other.value else other
-
-
 class Inputs(BaseModel):
 class Inputs(BaseModel):
     """Stub class describing input arguments"""
     """Stub class describing input arguments"""
 
 

+ 2 - 1
src/cipy/runner.py

@@ -15,7 +15,8 @@ from dotenv import dotenv_values
 
 
 import cipy.common
 import cipy.common
 from cipy import settings
 from cipy import settings
-from cipy.common import Context, Status
+from cipy.common import Context
+from cipy.status import Status
 
 
 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]

+ 15 - 0
src/cipy/status.py

@@ -0,0 +1,15 @@
+"""Status enum"""
+from enum import Enum, auto
+
+
+class Status(Enum):
+    """Result status of a runner, higher numbers take priority"""
+
+    NOT_RUN = auto()
+    SKIPPED = auto()
+    SUCCESS = auto()
+    FAILURE = auto()
+    CANCELLED = auto()
+
+    def __ior__(self, other: Status) -> Status:
+        return self if self.value > other.value else other

+ 2 - 1
src/cipy/workflow.py

@@ -9,7 +9,8 @@ from pydantic import BaseModel, PrivateAttr
 
 
 import cipy.runner
 import cipy.runner
 
 
-from cipy.common import Action, Context, Results, Scalar, Status, Value
+from cipy.common import Action, Context, Results, Scalar, Value
+from cipy.status import Status
 
 
 
 
 class Job(BaseModel):
 class Job(BaseModel):