コード例 #1
0
class CreateJobSpec(StrictJSONObject['CreateJobSpec']):
    """
    Specifies the JSON data structure for specifying the arguments
    to execute a job-template with.
    """
    # The values of the inputs
    input_values: Dict[str, ValueTypePair] = MapProperty(
        value_property=ValueTypePair.as_property())

    # The values of the parameters
    parameter_values: Dict[str,
                           str] = MapProperty(value_property=StringProperty(),
                                              optional=True)

    # A description of the job
    description: str = StringProperty(optional=True, default="")

    # The notification override for the top-level job
    notification_override: NotificationOverride = NotificationOverride.as_property(
        optional=True)

    # The notification overrides for child-jobs
    child_notification_overrides: Dict[
        str, NotificationOverride] = MapProperty(
            value_property=NotificationOverride.as_property(), optional=True)
コード例 #2
0
class JobTemplateSpec(StrictJSONObject['JobTemplateSpec']):
    """
    JSON document which specifies a job template.
    """
    # The name to give the template
    name: str = StringProperty(min_length=1, max_length=200)

    # The version to give the template (omit for latest version)
    version: int = NumberProperty(minimum=1, integer_only=True, optional=True)

    # A description of the task the template performs
    description: str = StringProperty(optional=True, default="")

    # The scope of the template
    scope: str = StringProperty(min_length=1, max_length=16)

    # The licence the template is issued under
    licence: str = StringProperty(min_length=1, max_length=100)

    # The domain of the template, if any
    domain: str = StringProperty(min_length=2, max_length=2, optional=True)

    # The specific information which determines what type of template is defined
    specific: Union[WorkableTemplateSpec,
                    DependencyGraph] = OneOfProperty(sub_properties=(
                        # Defines a base workable job template
                        WorkableTemplateSpec.as_property(),

                        # Defines a workflow meta-job template
                        DependencyGraph.as_property()))
コード例 #3
0
class WorkableTemplateSpec(StrictJSONObject['WorkableTemplateSpec']):
    """
    JSON document specifying parameters for a job template which
    can be worked by worker-nodes.
    """
    # The framework being used by the worker node, in 'name|version' format
    framework: str = StringProperty(min_length=3, max_length=49)

    # The type of job this template performs
    job_type: str = StringProperty(min_length=1, max_length=32)

    # The executor class responsible for executing this template
    executor_class: str = StringProperty(max_length=128)

    # Any packages that the executor class requires to complete the task
    required_packages: str = StringProperty()

    # The body of the job
    body: str = StringProperty()

    # Any inputs to the job required to perform the task
    inputs: List[InputSpec] = ArrayProperty(element_property=InputSpec.as_property())

    # Any parameters to the job required to perform the task
    parameters: List[ParameterSpec] = ArrayProperty(element_property=ParameterSpec.as_property())
コード例 #4
0
class EmailNotification(Notification['EmailNotification']):
    """
    Notification specification for sending an email.
    """
    # The subject of the email
    subject: str = StringProperty()

    # The body of the email
    body: str = StringProperty()

    # The recipients of the email (defaults to the job's creator if omitted)
    to: List[str] = ArrayProperty(element_property=StringProperty(),
                                  min_elements=1,
                                  unique_elements=True,
                                  optional=True)

    # Copied recipients of the email (defaults to no-one)
    cc: List[str] = ArrayProperty(element_property=StringProperty(),
                                  min_elements=1,
                                  unique_elements=True,
                                  optional=True)

    # Blind-copied recipients of the email (defaults to no-one)
    bcc: List[str] = ArrayProperty(element_property=StringProperty(),
                                   min_elements=1,
                                   unique_elements=True,
                                   optional=True)
コード例 #5
0
class TokenPair(StrictJSONObject['TokenPair']):
    """
    Represents a single token pair (access/refresh) as JSON.
    """
    # The access token
    access: str = StringProperty()

    # The refresh token
    refresh: str = StringProperty()
コード例 #6
0
class ValueTypePair(StrictJSONObject['ValueTypePair']):
    """
    A pair of a value and its type.
    """
    # The value passed to the input
    value: str = StringProperty()

    # The type of the value
    type: str = StringProperty()
コード例 #7
0
class FinishJobSpec(JSONObject['FinishJobSpec']):
    """
    Specifies the JSON data structure required to
    finish a job.
    """
    # Whether the job was successful
    success: bool = BoolProperty()

    # The type of notification to send
    send_notification: str = StringProperty()

    # Any error that occurred while running the job
    error: str = StringProperty(optional=True)
コード例 #8
0
class Node(StrictJSONObject['Node']):
    """
    A node in a dependency graph, indicating which template to use
    to create sub-jobs of the meta-template.
    """
    # The name of the job template to use for this node
    name: str = StringProperty(min_length=1, max_length=200)

    # The version of the template to use (uses the latest if omitted)
    version: int = NumberProperty(minimum=1, integer_only=True, optional=True)

    # The values to use as default for this node's parameters, overriding
    # the defaults defined on the child template
    parameter_default_overrides: Dict[str, str] = MapProperty(
        value_property=StringProperty(), optional=True)
コード例 #9
0
class JobOutputTypeSpec(StrictJSONObject['JobOutputTypeSpec']):
    """
    Specifies the JSON data structure for specifying the type
    of a job output.
    """
    # The type of the output
    type: str = StringProperty(max_length=64)
コード例 #10
0
class ParameterSpec(StrictJSONObject['ParameterSpec']):
    """
    Specifies the JSON data structure for specifying the type
    and default value to a parameter to a job template.
    """
    # The name of the parameter
    name: str = StringProperty(min_length=1, max_length=32)

    # The type of the parameter
    type: str = StringProperty(min_length=1, max_length=32)

    # The options to the parameter
    default: str = StringProperty(optional=True, default="")

    # The help text for the parameter
    help: str = StringProperty(optional=True, default="")
コード例 #11
0
class StartJobSpec(JSONObject['StartJobSpec']):
    """
    Specifies the JSON data structure required to
    start a job.
    """
    # The type of notification to send
    send_notification: str = StringProperty()
コード例 #12
0
class FieldFilterExpression(FilterExpression[SelfType], ABC):
    """
    Base class for filter expressions which operate on a
    particular field of a model.
    """
    # The field on which to operate
    field: str = StringProperty(min_length=1)

    def __and__(self, other):
        from ..logical import And

        if isinstance(other, And):
            return And(sub_expressions=[self] + other.sub_expressions)
        elif isinstance(other, FieldFilterExpression):
            return And(sub_expressions=[self, other])
        else:
            raise TypeError(
                f"Can't perform logical and between "
                f"{self.__class__.__name__} and {other.__class__.__name__}")

    def __or__(self, other):
        from ..logical import Or, And

        if isinstance(other, Or):
            return Or(sub_expressions=[self] + other.sub_expressions)
        elif isinstance(other, (And, FieldFilterExpression)):
            return Or(sub_expressions=[self, other])
        else:
            raise TypeError(
                f"Can't perform logical or between "
                f"{self.__class__.__name__} and {other.__class__.__name__}")
コード例 #13
0
class Annotation(StrictJSONObject['Annotation']):
    """
    Represents a single annotation in an image.
    """
    # The bounding-box of the annotation
    x: int = NumberProperty(integer_only=True)
    y: int = NumberProperty(integer_only=True)
    width: int = NumberProperty(minimum=0, integer_only=True)
    height: int = NumberProperty(minimum=0, integer_only=True)

    # The optional polygon for mask annotations
    polygon: Polygon = Polygon.as_property(optional=True)

    # The annotations label
    label: str = StringProperty(min_length=1)

    # The optional prefix for the annotation
    prefix: str = StringProperty(min_length=1, optional=True, default="Object")
コード例 #14
0
class InputSpec(StrictJSONObject['InputSpec']):
    """
    Specifies the JSON data structure for specifying the type
    and options to an input to a job template.
    """
    # The name of the input
    name: str = StringProperty(min_length=1)

    # The possible types of value the input expects
    types: List[str] = ArrayProperty(
        element_property=StringProperty(min_length=1),
        min_elements=1
    )

    # The options to the input
    options: str = StringProperty(optional=True, default="")

    # The help text for the input
    help: str = StringProperty(optional=True, default="")
コード例 #15
0
class MembershipModSpec(StrictJSONObject['MembershipModSpec']):
    """
    Message to modify the memberships of a team.
    """
    # The username of the membership to modify
    username: str = StringProperty(min_length=1)

    # The type of modification to make
    method: str = EnumProperty(values=("add", "remove", "update"))

    # The permissions to give the member (only required for 'add' and 'update',
    # defaults to read-only permission if not specified).
    permissions: str = EnumProperty(values=("R", "X", "W", "A"), optional=True, default="R")
コード例 #16
0
class OrderBy(StrictJSONObject['OrderBy']):
    """
    A filtering stage which specifies the list should be returned
    in order of some field on the model.
    """
    # The field to sort by
    field: str = StringProperty()

    # Whether to sort ascending (the default) or descending
    ascending: bool = BoolProperty(optional=True, default=True)

    # Whether null values are sorted to the beginning or end
    # of the sort order (default is undefined)
    nulls_first: bool = BoolProperty(optional=True)
コード例 #17
0
class CategoriesModSpec(StrictJSONObject['CategoriesModSpec']):
    """
    A specification of which images to modify the categories
    for, and which categories to modify for those images.
    """
    # The method to use to modify the categories
    method: str = EnumProperty(
        values=("add", "remove")
    )

    # The images to modify the categories for
    images: List[str] = ArrayProperty(
        element_property=StringProperty(min_length=1),
        min_elements=1,
        unique_elements=True
    )

    # The categories to add/remove from the images
    categories: List[str] = ArrayProperty(
        element_property=StringProperty(min_length=1),
        min_elements=1,
        unique_elements=True
    )
コード例 #18
0
class PretrainedModelMigrationSpec(JSONObject['PretrainedModelMigrationSpec']):
    """
    Represents the JSON structure used to specify a pre-trained model in
    the migration of the database.
    """
    name = StringProperty(min_length=1, max_length=200)
    description = StringProperty()
    url = StringProperty(min_length=1, max_length=200)
    licence = StringProperty(min_length=1, max_length=100)
    framework = StringProperty(min_length=3, max_length=49)
    domain = StringProperty(min_length=1, max_length=2)
    source = StringProperty()
    metadata = JSONObject.as_property()
コード例 #19
0
class Contains(FieldFilterExpression['Contains']):
    """
    Filter expression which filters the list to those entries
    whose field contains some sub-string.
    """
    # Keyword identifying this object as a 'contains' expression
    type: str = ConstantProperty(value="contains")

    # The sub-string to filter for
    sub_string: str = StringProperty(min_length=1)

    # Whether the filtering should be performed without regard to case
    case_insensitive: bool = BoolProperty(optional=True, default=False)

    def __init__(self, **initial_values):
        # Automatically supply the type argument
        initial_values.setdefault("type", "contains")

        super().__init__(**initial_values)
コード例 #20
0
class LicenceSubdescriptorModSpec(
        StrictJSONObject['LicenceSubdescriptorModSpec']):
    """
    Message to modify the sub-descriptors of a licence.
    """
    # The type of sub-descriptor to modify
    type: str = EnumProperty(values=("permissions", "conditions",
                                     "limitations", "domains"))

    # The type of modification to make
    method: str = EnumProperty(values=("add", "remove"))

    # The name of the sub-descriptor
    names: List[Union[str, int]] = ArrayProperty(
        element_property=OneOfProperty(
            sub_properties=(StringProperty(min_length=1, max_length=100),
                            NumberProperty(minimum=1, integer_only=True))),
        min_elements=1,
        unique_elements=True)
コード例 #21
0
class Compare(FieldFilterExpression['Compare']):
    """
    Filter expression which filters the list to those entries
    whose field compares to a given value (e.g. >, <, >=, <=).
    """
    # Keyword identifying this object as a 'compare' expression
    type: str = ConstantProperty(value="compare")

    # The type of comparison to perform
    operator: str = EnumProperty(values=("<", ">", ">=", "<="))

    # The value to compare to
    value: Union[str, int,
                 float] = OneOfProperty(sub_properties=(StringProperty(),
                                                        NumberProperty()))

    def __init__(self, **initial_values):
        # Automatically supply the type argument
        initial_values.setdefault("type", "compare")

        super().__init__(**initial_values)
コード例 #22
0
class Exact(FieldFilterExpression['Exact']):
    """
    Filter expression which filters the list to those entries
    whose field exactly matches some value.
    """
    # Keyword identifying this object as an 'exact' expression
    type: str = ConstantProperty(value="exact")

    # The value to match exactly
    value: Union[str, int, float,
                 bool] = OneOfProperty(sub_properties=(StringProperty(),
                                                       NumberProperty(),
                                                       BoolProperty()))

    # Whether the filtering should be performed without regard to case
    case_insensitive: bool = BoolProperty(optional=True, default=False)

    def __init__(self, **initial_values):
        # Automatically supply the type argument
        initial_values.setdefault("type", "exact")

        super().__init__(**initial_values)
コード例 #23
0
class Image(StrictJSONObject['Image']):
    """
    Represents a single image and its annotations.
    """
    # The image's format
    format: str = StringProperty(optional=True)

    # The image's dimensions
    dimensions: List[int] = ArrayProperty(element_property=NumberProperty(
        integer_only=True, minimum=1),
                                          min_elements=2,
                                          max_elements=2,
                                          optional=True)

    # The annotations of the image
    annotations: List[Annotation] = ArrayProperty(
        element_property=Annotation.as_property())

    @property
    def width(self) -> Optional[int]:
        """
        Gets the width from the dimensions.

        :return:    The width, or None if not available.
        """
        if self.dimensions is not Absent:
            return self.dimensions[0]

    @property
    def height(self) -> Optional[int]:
        """
        Gets the height from the dimensions.

        :return:    The height, or None if not available.
        """
        if self.dimensions is not Absent:
            return self.dimensions[1]
コード例 #24
0
class Transcription(StrictJSONObject['Transcription']):
    """
    The transcription of a single speech audio-file.
    """
    # The text of the transcription itself
    transcription = StringProperty(optional=True, default="")
コード例 #25
0
class PrintNotification(Notification['PrintNotification']):
    """
    Notification specification for printing to standard output.
    """
    # The message to print
    message: str = StringProperty()
コード例 #26
0
class FileMetadata(StrictJSONObject['FileMetadata']):
    """
    JSON object containing the meta-data for a file.
    """
    # The meta-data
    metadata = StringProperty()
コード例 #27
0
 def _additional_properties_validation(cls) -> ArrayProperty:
     return ArrayProperty(
         element_property=StringProperty(min_length=1),
         unique_elements=True,  # Each category should only appear once
         optional=True,
         default=[])