Unverified Commit 12c973b4 authored by Marius van den Beek's avatar Marius van den Beek Committed by mvdbeek
Browse files

Replace ResourceType Enum with Literal

parent 51c04849
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
import copy
from enum import Enum
from typing import (
    Callable,
    Dict,
@@ -7,6 +6,11 @@ from typing import (
    Union,
)

from typing_extensions import (
    get_args,
    Literal,
)

from galaxy.util import (
    asbool,
    xml_text,
@@ -211,18 +215,24 @@ class ContainerDescription:
        return f"ContainerDescription[identifier={self.identifier},type={self.type}]"


class ResourceType(str, Enum):
    cores_min = "cores_min"
    cores_max = "cores_max"
    ram_min = "ram_min"
    ram_max = "ram_max"
    tmpdir_min = "tmpdir_min"
    tmpdir_max = "tmpdir_max"
ResourceType = Literal[
    "cores_min",
    "cores_max",
    "ram_min",
    "ram_max",
    "tmpdir_min",
    "tmpdir_max",
]
VALID_RESOURCE_TYPES = get_args(ResourceType)


class ResourceRequirement:
    def __init__(self, value_or_expression: Union[int, float, str], resource_type: ResourceType):
        self.value_or_expression = value_or_expression
        if not resource_type:
            raise ValueError("Missing resource requirement type")
        if resource_type not in VALID_RESOURCE_TYPES:
            raise ValueError(f"Invalid resource requirement type '{resource_type}'")
        self.resource_type = resource_type
        self._runtime_required: Optional[bool] = None

@@ -316,7 +326,7 @@ def parse_requirements_from_xml(xml_root, parse_resources=False):

def resource_from_element(resource_elem):
    value_or_expression = xml_text(resource_elem)
    resource_type = resource_elem.get("type", DEFAULT_CONTAINER_TYPE)
    resource_type = resource_elem.get("type")
    return ResourceRequirement(value_or_expression=value_or_expression, resource_type=resource_type)


+1 −1
Original line number Diff line number Diff line
@@ -6778,7 +6778,7 @@ and ``bibtex`` are the only supported options.</xs:documentation>
      </xs:enumeration>
      <xs:enumeration value="tmpdir_max">
        <xs:annotation>
          <xs:documentation xml:lang="en">Maximum reserved filesystem based storage for the designated temporary directory, in mebibytes (2**20) if runtime allows it (unimplemented in Galaxy currently).</xs:documentation>
          <xs:documentation xml:lang="en">Maximum reserved filesystem based storage for the designated temporary directory in mebibytes (2**20 bytes), if runtime allows it (unimplemented in Galaxy currently).</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>