Skip to content

Commit

Permalink
use StrEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Oct 1, 2024
1 parent 2fc280e commit 2a705ee
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions antarest/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import multiprocessing
import tempfile
from dataclasses import asdict, dataclass, field
from enum import Enum
from enum import StrEnum
from pathlib import Path
from typing import Dict, List, Optional

Expand All @@ -25,7 +25,7 @@
DEFAULT_WORKSPACE_NAME = "default"


class Launcher(str, Enum):
class Launcher(StrEnum):
SLURM = "slurm"
LOCAL = "local"
DEFAULT = "default"
Expand Down
4 changes: 2 additions & 2 deletions antarest/core/configdata/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This file is part of the Antares project.

from enum import Enum
from enum import StrEnum
from typing import Any, Optional

from pydantic import BaseModel
Expand Down Expand Up @@ -43,6 +43,6 @@ def to_dto(self) -> ConfigDataDTO:


# APP MAIN CONFIG KEYS
class ConfigDataAppKeys(str, Enum):
class ConfigDataAppKeys(StrEnum):
MAINTENANCE_MODE = "MAINTENANCE_MODE"
MESSAGE_INFO = "MESSAGE_INFO"
4 changes: 2 additions & 2 deletions antarest/core/interfaces/eventbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
# This file is part of the Antares project.

from abc import ABC, abstractmethod
from enum import Enum
from enum import StrEnum
from typing import Any, Awaitable, Callable, List, Optional

from pydantic import BaseModel

from antarest.core.model import PermissionInfo


class EventType(str, Enum):
class EventType(StrEnum):
ANY = "_ANY"
STUDY_CREATED = "STUDY_CREATED"
STUDY_DELETED = "STUDY_DELETED"
Expand Down
4 changes: 2 additions & 2 deletions antarest/core/maintenance/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#
# This file is part of the Antares project.

from enum import Enum
from enum import StrEnum


class MaintenanceMode(str, Enum):
class MaintenanceMode(StrEnum):
NORMAL_MODE = "NORMAL"
MAINTENANCE_MODE = "MAINTENANCE"

Expand Down
4 changes: 2 additions & 2 deletions antarest/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
SUB_JSON = Union[ELEMENT, JSON, List[Any], None]


class PublicMode(str, enum.Enum):
class PublicMode(enum.StrEnum):
NONE = "NONE"
READ = "READ"
EXECUTE = "EXECUTE"
EDIT = "EDIT"
FULL = "FULL"


class StudyPermissionType(str, enum.Enum):
class StudyPermissionType(enum.StrEnum):
"""
User permission belongs to Study
"""
Expand Down
4 changes: 2 additions & 2 deletions antarest/core/tasks/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import typing as t
import uuid
from datetime import datetime
from enum import Enum
from enum import Enum, StrEnum

from pydantic import BaseModel
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, Sequence, String # type: ignore
Expand All @@ -28,7 +28,7 @@
from antarest.study.model import Study


class TaskType(str, Enum):
class TaskType(StrEnum):
EXPORT = "EXPORT"
VARIANT_GENERATION = "VARIANT_GENERATION"
COPY = "COPY"
Expand Down
4 changes: 2 additions & 2 deletions antarest/eventbus/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import dataclasses
import logging
from enum import Enum
from enum import StrEnum
from http import HTTPStatus
from typing import List, Optional

Expand All @@ -33,7 +33,7 @@
logger = logging.getLogger(__name__)


class WebsocketMessageAction(str, Enum):
class WebsocketMessageAction(StrEnum):
SUBSCRIBE = "SUBSCRIBE"
UNSUBSCRIBE = "UNSUBSCRIBE"

Expand Down
6 changes: 3 additions & 3 deletions antarest/launcher/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def from_launcher_params(cls, params: t.Optional[str]) -> "LauncherParametersDTO
return cls.model_validate(from_json(params))


class LogType(str, enum.Enum):
class LogType(enum.StrEnum):
STDOUT = "STDOUT"
STDERR = "STDERR"

Expand All @@ -79,14 +79,14 @@ def to_suffix(self) -> str:
return "out.log"


class JobStatus(str, enum.Enum):
class JobStatus(enum.StrEnum):
PENDING = "pending"
FAILED = "failed"
SUCCESS = "success"
RUNNING = "running"


class JobLogType(str, enum.Enum):
class JobLogType(enum.StrEnum):
BEFORE = "BEFORE"
AFTER = "AFTER"

Expand Down
4 changes: 2 additions & 2 deletions antarest/service_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import logging
import typing as t
from enum import Enum
from enum import StrEnum
from pathlib import Path

import redis
Expand Down Expand Up @@ -67,7 +67,7 @@
"""


class Module(str, Enum):
class Module(StrEnum):
APP = "app"
WATCHER = "watcher"
MATRIX_GC = "matrix_gc"
Expand Down
12 changes: 6 additions & 6 deletions antarest/study/business/aggregator_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import logging
import typing as t
from enum import Enum
from enum import StrEnum
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -54,31 +54,31 @@
logger = logging.getLogger(__name__)


class MCRoot(str, Enum):
class MCRoot(StrEnum):
MC_IND = "mc-ind"
MC_ALL = "mc-all"


class MCIndAreasQueryFile(str, Enum):
class MCIndAreasQueryFile(StrEnum):
VALUES = "values"
DETAILS = "details"
DETAILS_ST_STORAGE = "details-STstorage"
DETAILS_RES = "details-res"


class MCAllAreasQueryFile(str, Enum):
class MCAllAreasQueryFile(StrEnum):
VALUES = "values"
DETAILS = "details"
DETAILS_ST_STORAGE = "details-STstorage"
DETAILS_RES = "details-res"
ID = "id"


class MCIndLinksQueryFile(str, Enum):
class MCIndLinksQueryFile(StrEnum):
VALUES = "values"


class MCAllLinksQueryFile(str, Enum):
class MCAllLinksQueryFile(StrEnum):
VALUES = "values"
ID = "id"

Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/enum_ignore_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import typing


class EnumIgnoreCase(str, enum.Enum):
class EnumIgnoreCase(enum.StrEnum):
"""
Case-insensitive enum base class
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/scenario_builder_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Rulesets: te.TypeAlias = t.MutableMapping[str, Ruleset]


class ScenarioType(str, enum.Enum):
class ScenarioType(enum.StrEnum):
"""
Scenario type
Expand Down
6 changes: 3 additions & 3 deletions antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ class StudySimResultDTO(BaseModel):
archived: bool


class StudyDownloadType(str, enum.Enum):
class StudyDownloadType(enum.StrEnum):
LINK = "LINK"
DISTRICT = "DISTRICT"
AREA = "AREA"


class StudyDownloadLevelDTO(str, enum.Enum):
class StudyDownloadLevelDTO(enum.StrEnum):
ANNUAL = "annual"
MONTHLY = "monthly"
WEEKLY = "weekly"
Expand All @@ -440,7 +440,7 @@ def inc_date(self, date: datetime) -> datetime:
raise ShouldNotHappenException()


class ExportFormat(str, enum.Enum):
class ExportFormat(enum.StrEnum):
ZIP = "application/zip"
TAR_GZ = "application/tar+gz"
JSON = "application/json"
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class StudyFilter(BaseModel, frozen=True, extra="forbid"):
access_permissions: AccessPermissions = AccessPermissions()


class StudySortBy(str, enum.Enum):
class StudySortBy(enum.StrEnum):
"""How to sort the results of studies query results"""

NAME_ASC = "+name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import logging
from abc import ABC, abstractmethod
from enum import Enum
from enum import StrEnum
from pathlib import Path
from typing import Any, List, Optional, Union, cast

Expand All @@ -27,7 +27,7 @@
logger = logging.getLogger(__name__)


class MatrixFrequency(str, Enum):
class MatrixFrequency(StrEnum):
"""
An enumeration of matrix frequencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def build(self) -> TREE:
freq: MatrixFrequency
for freq in MatrixFrequency:
for output_type in ["id", "values", "details", "details-res", "details-STstorage"]:
file_name = f"{output_type}-{freq.value}.txt"
file_name = f"{output_type}-{freq}.txt"
if (self.config.path / file_name).exists():
children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix(
children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix(
self.context,
self.config.next_file(file_name),
freq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def build(self) -> TREE:
freq: MatrixFrequency
for freq in MatrixFrequency:
for output_type in ["id", "values"]:
file_name = f"{output_type}-{freq.value}.txt"
file_name = f"{output_type}-{freq}.txt"
if (self.config.path / file_name).exists():
children[f"{output_type}-{freq.value}"] = LinkOutputSeriesMatrix(
children[f"{output_type}-{freq}"] = LinkOutputSeriesMatrix(
self.context,
self.config.next_file(file_name),
freq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def build(self) -> TREE:
freq: MatrixFrequency
for freq in MatrixFrequency:
for output_type in ["id", "values"]:
file_name = f"{output_type}-{freq.value}.txt"
file_name = f"{output_type}-{freq}.txt"
if (self.config.path / file_name).exists():
children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix(
children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix(
self.context,
self.config.next_file(file_name),
freq,
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/web/study_data_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class BCKeyValueType(te.TypedDict):
value: t.Union[str, int, float, bool]


class ClusterType(str, enum.Enum):
class ClusterType(enum.StrEnum):
"""
Cluster type:
Expand Down

0 comments on commit 2a705ee

Please sign in to comment.