From 2a705eeac5d6bcbd6606e3a61d22406ba19eb4ac Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:16:32 +0200 Subject: [PATCH] use StrEnum --- antarest/core/config.py | 4 ++-- antarest/core/configdata/model.py | 4 ++-- antarest/core/interfaces/eventbus.py | 4 ++-- antarest/core/maintenance/model.py | 4 ++-- antarest/core/model.py | 4 ++-- antarest/core/tasks/model.py | 4 ++-- antarest/eventbus/web.py | 4 ++-- antarest/launcher/model.py | 6 +++--- antarest/service_creator.py | 4 ++-- antarest/study/business/aggregator_management.py | 12 ++++++------ antarest/study/business/enum_ignore_case.py | 2 +- .../study/business/scenario_builder_management.py | 2 +- antarest/study/model.py | 6 +++--- antarest/study/repository.py | 2 +- .../rawstudy/model/filesystem/matrix/matrix.py | 4 ++-- .../root/output/simulation/mode/common/area.py | 4 ++-- .../root/output/simulation/mode/common/link.py | 4 ++-- .../root/output/simulation/mode/common/set.py | 4 ++-- antarest/study/web/study_data_blueprint.py | 2 +- 19 files changed, 40 insertions(+), 40 deletions(-) diff --git a/antarest/core/config.py b/antarest/core/config.py index 4b85331d6a..0f76ef0be4 100644 --- a/antarest/core/config.py +++ b/antarest/core/config.py @@ -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 @@ -25,7 +25,7 @@ DEFAULT_WORKSPACE_NAME = "default" -class Launcher(str, Enum): +class Launcher(StrEnum): SLURM = "slurm" LOCAL = "local" DEFAULT = "default" diff --git a/antarest/core/configdata/model.py b/antarest/core/configdata/model.py index 3e0d6b970e..af599d8861 100644 --- a/antarest/core/configdata/model.py +++ b/antarest/core/configdata/model.py @@ -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 @@ -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" diff --git a/antarest/core/interfaces/eventbus.py b/antarest/core/interfaces/eventbus.py index 10965ea831..8ac715e459 100644 --- a/antarest/core/interfaces/eventbus.py +++ b/antarest/core/interfaces/eventbus.py @@ -11,7 +11,7 @@ # 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 @@ -19,7 +19,7 @@ from antarest.core.model import PermissionInfo -class EventType(str, Enum): +class EventType(StrEnum): ANY = "_ANY" STUDY_CREATED = "STUDY_CREATED" STUDY_DELETED = "STUDY_DELETED" diff --git a/antarest/core/maintenance/model.py b/antarest/core/maintenance/model.py index c133e4ea9f..c17beadbc3 100644 --- a/antarest/core/maintenance/model.py +++ b/antarest/core/maintenance/model.py @@ -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" diff --git a/antarest/core/model.py b/antarest/core/model.py index b500e9a5c5..b086745064 100644 --- a/antarest/core/model.py +++ b/antarest/core/model.py @@ -24,7 +24,7 @@ SUB_JSON = Union[ELEMENT, JSON, List[Any], None] -class PublicMode(str, enum.Enum): +class PublicMode(enum.StrEnum): NONE = "NONE" READ = "READ" EXECUTE = "EXECUTE" @@ -32,7 +32,7 @@ class PublicMode(str, enum.Enum): FULL = "FULL" -class StudyPermissionType(str, enum.Enum): +class StudyPermissionType(enum.StrEnum): """ User permission belongs to Study """ diff --git a/antarest/core/tasks/model.py b/antarest/core/tasks/model.py index a7ca9aedb9..7c73506604 100644 --- a/antarest/core/tasks/model.py +++ b/antarest/core/tasks/model.py @@ -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 @@ -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" diff --git a/antarest/eventbus/web.py b/antarest/eventbus/web.py index a04a4571bb..d997e1251d 100644 --- a/antarest/eventbus/web.py +++ b/antarest/eventbus/web.py @@ -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 @@ -33,7 +33,7 @@ logger = logging.getLogger(__name__) -class WebsocketMessageAction(str, Enum): +class WebsocketMessageAction(StrEnum): SUBSCRIBE = "SUBSCRIBE" UNSUBSCRIBE = "UNSUBSCRIBE" diff --git a/antarest/launcher/model.py b/antarest/launcher/model.py index b26a502795..5096228635 100644 --- a/antarest/launcher/model.py +++ b/antarest/launcher/model.py @@ -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" @@ -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" diff --git a/antarest/service_creator.py b/antarest/service_creator.py index 5859806a61..04d9da626a 100644 --- a/antarest/service_creator.py +++ b/antarest/service_creator.py @@ -12,7 +12,7 @@ import logging import typing as t -from enum import Enum +from enum import StrEnum from pathlib import Path import redis @@ -67,7 +67,7 @@ """ -class Module(str, Enum): +class Module(StrEnum): APP = "app" WATCHER = "watcher" MATRIX_GC = "matrix_gc" diff --git a/antarest/study/business/aggregator_management.py b/antarest/study/business/aggregator_management.py index 7f961f7e91..df5bbaa30b 100644 --- a/antarest/study/business/aggregator_management.py +++ b/antarest/study/business/aggregator_management.py @@ -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 @@ -54,19 +54,19 @@ 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" @@ -74,11 +74,11 @@ class MCAllAreasQueryFile(str, Enum): ID = "id" -class MCIndLinksQueryFile(str, Enum): +class MCIndLinksQueryFile(StrEnum): VALUES = "values" -class MCAllLinksQueryFile(str, Enum): +class MCAllLinksQueryFile(StrEnum): VALUES = "values" ID = "id" diff --git a/antarest/study/business/enum_ignore_case.py b/antarest/study/business/enum_ignore_case.py index 2259d229f7..9d0bcf3396 100644 --- a/antarest/study/business/enum_ignore_case.py +++ b/antarest/study/business/enum_ignore_case.py @@ -14,7 +14,7 @@ import typing -class EnumIgnoreCase(str, enum.Enum): +class EnumIgnoreCase(enum.StrEnum): """ Case-insensitive enum base class diff --git a/antarest/study/business/scenario_builder_management.py b/antarest/study/business/scenario_builder_management.py index c8a38b28c3..ac5a6a2bb6 100644 --- a/antarest/study/business/scenario_builder_management.py +++ b/antarest/study/business/scenario_builder_management.py @@ -37,7 +37,7 @@ Rulesets: te.TypeAlias = t.MutableMapping[str, Ruleset] -class ScenarioType(str, enum.Enum): +class ScenarioType(enum.StrEnum): """ Scenario type diff --git a/antarest/study/model.py b/antarest/study/model.py index 081fd48b4a..b7e7435f6f 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -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" @@ -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" diff --git a/antarest/study/repository.py b/antarest/study/repository.py index f4d2e691c1..3b21511e0b 100644 --- a/antarest/study/repository.py +++ b/antarest/study/repository.py @@ -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" diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py index 364a5e3524..95d994d7df 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py @@ -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 @@ -27,7 +27,7 @@ logger = logging.getLogger(__name__) -class MatrixFrequency(str, Enum): +class MatrixFrequency(StrEnum): """ An enumeration of matrix frequencies. diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py index f42637b298..0b97fa5735 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py @@ -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, diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py index e3b83c1349..b5f0b15dcb 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py @@ -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, diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py index 7ac2b3cd5e..4c8a624a5c 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py @@ -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, diff --git a/antarest/study/web/study_data_blueprint.py b/antarest/study/web/study_data_blueprint.py index 2128ed849c..a6d39c7164 100644 --- a/antarest/study/web/study_data_blueprint.py +++ b/antarest/study/web/study_data_blueprint.py @@ -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: