"""
The procedures module defines a representation of the
procedures listed in the activities of the SKA scheduling block.
"""
from abc import ABC, abstractmethod
from typing import Literal, Optional, Union
from pydantic import Field
from typing_extensions import Annotated
from ska_oso_pdm._shared import PdmObject, PythonArguments, TerseStrEnum
__all__ = ["ProcedureUnion", "InlineScript", "FilesystemScript", "GitScript"]
class ScriptKind(TerseStrEnum):
INLINE = "inline"
FILESYSTEM = "filesystem"
GIT = "git"
class PythonProcedure(PdmObject, ABC):
"""
Represents a PythonProcedure to be run as an activity in an SKA scheduling block.
"""
@classmethod
@property
@abstractmethod # flake8: F821
def kind(cls) -> str:
"""
Discriminator field used to distinguish the subclass type of instances that
extend PythonProcedure. This field is a requirement of the JSON
representation, allowing the correct class to be instantiated as the JSON is
unmarshalled.
kind is an abstract class property and must be defined in any subclass.
"""
# 'raise NotImplementedError' causes an error in docs
pass # pylint: disable=unnecessary-pass
function_args: dict[str, PythonArguments] = Field(default_factory=dict)
[docs]
class InlineScript(PythonProcedure):
"""
Represents an InlineScript to be ran as an activity in an SKA scheduling block.
"""
kind: Literal[ScriptKind.INLINE] = ScriptKind.INLINE
content: str
[docs]
class FilesystemScript(PythonProcedure):
"""
Represents an FilesystemScript to be run as an activity in an SKA scheduling block.
"""
kind: Literal[ScriptKind.FILESYSTEM] = ScriptKind.FILESYSTEM
path: str
[docs]
class GitScript(FilesystemScript):
"""
Represents an GitScript to be run as an activity in an SKA scheduling block.
"""
kind: Literal[ScriptKind.GIT] = ScriptKind.GIT
repo: str
path: str
branch: Optional[str] = None
commit: Optional[str] = None
ProcedureUnion = Annotated[
Union[InlineScript, FilesystemScript, GitScript], Field(discriminator="kind")
]