From 2467479a909bd423dabe28c8bf69004045031e1b Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Wed, 4 Dec 2024 13:05:54 +0100 Subject: [PATCH] Remove code paths for python <3.11 --- src/_ert/events.py | 8 +------- src/ert/config/parsing/analysis_mode.py | 2 +- src/ert/config/parsing/config_keywords.py | 2 +- src/ert/config/parsing/config_schema_item.py | 3 +-- src/ert/config/parsing/forward_model_keywords.py | 2 +- src/ert/config/parsing/history_source.py | 2 +- src/ert/config/parsing/hook_runtime.py | 2 +- src/ert/config/parsing/queue_system.py | 2 +- src/ert/config/parsing/schema_item_type.py | 2 +- src/ert/config/parsing/workflow_job_keywords.py | 2 +- src/ert/config/parsing/workflow_keywords.py | 2 +- src/ert/dark_storage/json_schema/prior.py | 8 +------- src/ert/enum_shim.py | 13 ------------- src/ert/field_utils/field_file_format.py | 2 +- src/ert/gui/main.py | 10 ++-------- src/everest/docs/generate_docs_from_config_spec.py | 6 ------ src/everest/export.py | 11 +---------- tests/ert/conftest.py | 12 +++--------- .../entry_points/test_visualization_entry.py | 4 ---- 19 files changed, 19 insertions(+), 76 deletions(-) delete mode 100644 src/ert/enum_shim.py diff --git a/src/_ert/events.py b/src/_ert/events.py index cebe3c5d47f..1092e14c7fb 100644 --- a/src/_ert/events.py +++ b/src/_ert/events.py @@ -1,11 +1,5 @@ -import sys from datetime import datetime -from typing import Any, Dict, Final, Literal, Union - -if sys.version_info < (3, 9): - from typing_extensions import Annotated -else: - from typing import Annotated +from typing import Annotated, Any, Dict, Final, Literal, Union from pydantic import BaseModel, ConfigDict, Field, TypeAdapter diff --git a/src/ert/config/parsing/analysis_mode.py b/src/ert/config/parsing/analysis_mode.py index 75172b83480..e88a97a25a5 100644 --- a/src/ert/config/parsing/analysis_mode.py +++ b/src/ert/config/parsing/analysis_mode.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class AnalysisMode(StrEnum): diff --git a/src/ert/config/parsing/config_keywords.py b/src/ert/config/parsing/config_keywords.py index 956216b7c5f..3cf8e46839e 100644 --- a/src/ert/config/parsing/config_keywords.py +++ b/src/ert/config/parsing/config_keywords.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class ConfigKeys(StrEnum): diff --git a/src/ert/config/parsing/config_schema_item.py b/src/ert/config/parsing/config_schema_item.py index a7947800744..cc980bef7b1 100644 --- a/src/ert/config/parsing/config_schema_item.py +++ b/src/ert/config/parsing/config_schema_item.py @@ -1,12 +1,11 @@ import os import shutil +from enum import EnumType from typing import List, Mapping, Optional, TypeVar, Union from pydantic import ConfigDict, Field, NonNegativeInt, PositiveInt from pydantic.dataclasses import dataclass -from ert.enum_shim import EnumType - from .config_errors import ConfigValidationError from .context_values import ( ContextBool, diff --git a/src/ert/config/parsing/forward_model_keywords.py b/src/ert/config/parsing/forward_model_keywords.py index 75c6367c2b5..f06b10d684e 100644 --- a/src/ert/config/parsing/forward_model_keywords.py +++ b/src/ert/config/parsing/forward_model_keywords.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class ForwardModelStepKeys(StrEnum): diff --git a/src/ert/config/parsing/history_source.py b/src/ert/config/parsing/history_source.py index fa04c9165ee..16e2a608479 100644 --- a/src/ert/config/parsing/history_source.py +++ b/src/ert/config/parsing/history_source.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class HistorySource(StrEnum): diff --git a/src/ert/config/parsing/hook_runtime.py b/src/ert/config/parsing/hook_runtime.py index 9a5d854c66d..b6e1c9505db 100644 --- a/src/ert/config/parsing/hook_runtime.py +++ b/src/ert/config/parsing/hook_runtime.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class HookRuntime(StrEnum): diff --git a/src/ert/config/parsing/queue_system.py b/src/ert/config/parsing/queue_system.py index 1de41bce8d7..13730f76285 100644 --- a/src/ert/config/parsing/queue_system.py +++ b/src/ert/config/parsing/queue_system.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class QueueSystem(StrEnum): diff --git a/src/ert/config/parsing/schema_item_type.py b/src/ert/config/parsing/schema_item_type.py index e67037b59c4..7b7c5dafb79 100644 --- a/src/ert/config/parsing/schema_item_type.py +++ b/src/ert/config/parsing/schema_item_type.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class SchemaItemType(StrEnum): diff --git a/src/ert/config/parsing/workflow_job_keywords.py b/src/ert/config/parsing/workflow_job_keywords.py index 5b8cbb38f13..087ff5a927f 100644 --- a/src/ert/config/parsing/workflow_job_keywords.py +++ b/src/ert/config/parsing/workflow_job_keywords.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class WorkflowJobKeys(StrEnum): diff --git a/src/ert/config/parsing/workflow_keywords.py b/src/ert/config/parsing/workflow_keywords.py index 79b31177ec1..4e72cffbcfa 100644 --- a/src/ert/config/parsing/workflow_keywords.py +++ b/src/ert/config/parsing/workflow_keywords.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class WorkflowKeys(StrEnum): diff --git a/src/ert/dark_storage/json_schema/prior.py b/src/ert/dark_storage/json_schema/prior.py index b22bfc5b735..3a240e9ab3a 100644 --- a/src/ert/dark_storage/json_schema/prior.py +++ b/src/ert/dark_storage/json_schema/prior.py @@ -1,13 +1,7 @@ -import sys -from typing import Union +from typing import Literal, Union from pydantic import BaseModel -if sys.version_info < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal - class PriorConst(BaseModel): """ diff --git a/src/ert/enum_shim.py b/src/ert/enum_shim.py deleted file mode 100644 index c02184419ee..00000000000 --- a/src/ert/enum_shim.py +++ /dev/null @@ -1,13 +0,0 @@ -import sys - -if sys.version_info < (3, 11): - from enum import Enum - from enum import EnumMeta as EnumType - - class StrEnum(str, Enum): - pass - -else: - from enum import EnumType, StrEnum - -__all__ = ["EnumType", "StrEnum"] diff --git a/src/ert/field_utils/field_file_format.py b/src/ert/field_utils/field_file_format.py index 1fc3abb63b3..9e0a58893f3 100644 --- a/src/ert/field_utils/field_file_format.py +++ b/src/ert/field_utils/field_file_format.py @@ -1,4 +1,4 @@ -from ert.enum_shim import StrEnum +from enum import StrEnum class FieldFileFormat(StrEnum): diff --git a/src/ert/gui/main.py b/src/ert/gui/main.py index 48cc56c4394..dbcb6ca8b18 100755 --- a/src/ert/gui/main.py +++ b/src/ert/gui/main.py @@ -2,17 +2,11 @@ import logging import os -import sys +from collections import Counter +from importlib.resources import files from signal import SIG_DFL, SIGINT, signal from typing import Optional, Tuple -if sys.version_info >= (3, 9): - from importlib.resources import files -else: - from importlib_resources import files - -from collections import Counter - from qtpy.QtCore import QDir from qtpy.QtGui import QIcon from qtpy.QtWidgets import QApplication, QWidget diff --git a/src/everest/docs/generate_docs_from_config_spec.py b/src/everest/docs/generate_docs_from_config_spec.py index 766bc9dbf89..7c28287bfec 100644 --- a/src/everest/docs/generate_docs_from_config_spec.py +++ b/src/everest/docs/generate_docs_from_config_spec.py @@ -37,12 +37,6 @@ def doc_description(self) -> str: ) def clean_type(self) -> str: - if sys.version_info < (3, 10): - self.type = self.type.replace("Annotated[int, Ge(ge=0)]", "NonNegativeInt") - self.type = self.type.replace("Annotated[int, Gt(gt=0)]", "PositiveInt") - self.type = self.type.replace("Annotated[float, Gt(gt=0)]", "PositiveFloat") - self.type = re.sub(r"Union\[(.+),\s+NoneType\]", r"Optional[\1]", self.type) - self.type = self.type.replace("Annotated[int, Ge]", "NonNegativeInt") self.type = self.type.replace("Annotated[int, Gt]", "PositiveInt") self.type = self.type.replace("Annotated[float, Gt]", "PositiveFloat") diff --git a/src/everest/export.py b/src/everest/export.py index 5f10771a307..1c64a2fa75e 100644 --- a/src/everest/export.py +++ b/src/everest/export.py @@ -1,6 +1,6 @@ import os import re -import sys +from enum import StrEnum from typing import Any, Dict, List, Optional, Set import pandas as pd @@ -11,15 +11,6 @@ from everest.config import ExportConfig from everest.strings import STORAGE_DIR -if sys.version_info < (3, 11): - from enum import Enum - - class StrEnum(str, Enum): - pass - -else: - from enum import StrEnum - class MetaDataColumnNames(StrEnum): # NOTE: Always add a new column name to the list below! diff --git a/tests/ert/conftest.py b/tests/ert/conftest.py index 1d5036137a1..8d8d5f528b7 100644 --- a/tests/ert/conftest.py +++ b/tests/ert/conftest.py @@ -6,24 +6,18 @@ import shutil import sys from argparse import ArgumentParser +from importlib.resources import files from pathlib import Path from unittest.mock import MagicMock -from qtpy.QtWidgets import QApplication - -from _ert.threading import set_signal_handler - -if sys.version_info >= (3, 9): - from importlib.resources import files -else: - from importlib_resources import files - import pytest from hypothesis import HealthCheck, settings from hypothesis import strategies as st from qtpy.QtCore import QDir +from qtpy.QtWidgets import QApplication import _ert.forward_model_runner.cli +from _ert.threading import set_signal_handler from ert.__main__ import ert_parser from ert.cli.main import run_cli from ert.config import ErtConfig diff --git a/tests/everest/entry_points/test_visualization_entry.py b/tests/everest/entry_points/test_visualization_entry.py index 8bdc49ad717..b8d35933743 100644 --- a/tests/everest/entry_points/test_visualization_entry.py +++ b/tests/everest/entry_points/test_visualization_entry.py @@ -1,9 +1,6 @@ -import sys from pathlib import Path from unittest.mock import patch -import pytest - from everest.bin.visualization_script import visualization_entry from everest.detached import ServerStatus from tests.everest.utils import capture_streams @@ -13,7 +10,6 @@ "everest.bin.visualization_script.everserver_status", return_value={"status": ServerStatus.completed}, ) -@pytest.mark.skipif(sys.version_info.major < 3, reason="requires python3 or higher") def test_visualization_entry(_, cached_example): config_path, config_file, _ = cached_example("math_func/config_advanced.yml") with capture_streams() as (out, _):