Skip to content

Commit

Permalink
ruff pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Dec 11, 2024
1 parent 5b5ae1c commit d4a47f5
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/ert/resources/forward_models/run_reservoirsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections import namedtuple
from pathlib import Path
from random import random
from typing import List, Literal, Optional, Union, get_args
from typing import Literal, get_args

import resfo

Expand Down Expand Up @@ -59,7 +59,7 @@ def failed_due_to_license_problems(self) -> bool:
slave_run_paths = r"\s@\s+STARTING SLAVE .* RUNNING (\w+)\s*^\s@\s+ON HOST.*IN DIRECTORY\s*^\s@\s+(.*)"


def find_unsmry(basepath: Path) -> Optional[Path]:
def find_unsmry(basepath: Path) -> Path | None:
def _is_unsmry(base: str, path: str) -> bool:
if "." not in path:
return False
Expand All @@ -70,7 +70,7 @@ def _is_unsmry(base: str, path: str) -> bool:
]

base = basepath.name
candidates: List[str] = list(
candidates: list[str] = list(
filter(lambda x: _is_unsmry(base, x), glob.glob(str(basepath) + "*"))
)
if not candidates:
Expand Down Expand Up @@ -133,8 +133,8 @@ class RunReservoirSimulator:
def __init__(
self,
simulator: Simulators,
version: Optional[str],
ecl_case: Union[Path, str],
version: str | None,
ecl_case: Path | str,
num_cpu: int = 1,
check_status: bool = True,
summary_conversion: bool = False,
Expand All @@ -144,15 +144,15 @@ def __init__(
f"Unknown simulator '{simulator}', pick from {get_args(Simulators)}"
)
self.simulator = simulator
self.version: Optional[str] = version
self.version: str | None = version

self.num_cpu: int = int(num_cpu)
self.check_status: bool = check_status
self.summary_conversion: bool = summary_conversion

self.bypass_flowrun: bool = False

_runner_abspath: Optional[Union[str, Path]] = None
_runner_abspath: str | Path | None = None
if simulator in ["eclipse", "e300"]:
_eclrun_path: str = os.environ.get("ECLRUN_PATH", "")
_runner_abspath = shutil.which(Path(_eclrun_path) / "eclrun")
Expand All @@ -175,7 +175,7 @@ def __init__(

data_file = ecl_case_to_data_file(Path(ecl_case))
if not Path(data_file).exists():
raise IOError(f"No such file: {data_file}")
raise OSError(f"No such file: {data_file}")

self.run_path: Path = Path(data_file).parent.absolute()
self.data_file: str = Path(data_file).name
Expand All @@ -186,7 +186,7 @@ def prt_path(self) -> Path:
return self.run_path / (self.base_name + ".PRT")

@property
def eclrun_command(self) -> List[str]:
def eclrun_command(self) -> list[str]:
return [
self.runner_abspath,
self.simulator,
Expand All @@ -199,7 +199,7 @@ def eclrun_command(self) -> List[str]:
]

@property
def flowrun_command(self) -> List[str]:
def flowrun_command(self) -> list[str]:
if self.bypass_flowrun:
return [
self.runner_abspath,
Expand Down Expand Up @@ -238,7 +238,7 @@ def run_flow(self) -> None:
LICENSE_RETRY_BACKOFF_EXPONENT = 3

def run_eclipseX00(
self, retries_left: int = 3, backoff_sleep: Optional[float] = None
self, retries_left: int = 3, backoff_sleep: float | None = None
) -> None:
# This function calls itself recursively in case of license failures
backoff_sleep = (
Expand Down Expand Up @@ -321,7 +321,7 @@ def readECLEND(self) -> EclipseResult:

errors = None
bugs = None
with open(report_file, "r", encoding="utf-8") as filehandle:
with open(report_file, encoding="utf-8") as filehandle:
for line in filehandle.readlines():
error_match = re.match(error_regexp, line)
if error_match:
Expand All @@ -337,13 +337,13 @@ def readECLEND(self) -> EclipseResult:

return EclipseResult(errors=errors, bugs=bugs)

def parseErrors(self) -> List[str]:
def parseErrors(self) -> list[str]:
"""Extract multiline ERROR messages from the PRT file"""
error_list = []
error_e100_regexp = re.compile(error_pattern_e100, re.MULTILINE)
error_e300_regexp = re.compile(error_pattern_e300, re.MULTILINE)
slave_started_regexp = re.compile(slave_started_pattern, re.MULTILINE)
with open(self.prt_path, "r", encoding="utf-8") as filehandle:
with open(self.prt_path, encoding="utf-8") as filehandle:
content = filehandle.read()

for regexp in [error_e100_regexp, error_e300_regexp, slave_started_regexp]:
Expand Down Expand Up @@ -372,7 +372,7 @@ def tail_textfile(file_path: Path, num_chars: int) -> str:
return file.read()[-num_chars:]


def run_reservoirsimulator(args: List[str]) -> None:
def run_reservoirsimulator(args: list[str]) -> None:
parser = ArgumentParser()
parser.add_argument("simulator", type=str, choices=["flow", "eclipse", "e300"])
parser.add_argument("version", type=str)
Expand Down

0 comments on commit d4a47f5

Please sign in to comment.