From 4f1a570dcc7285222d203dc0adbafb5ef6b084b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Fri, 26 Jan 2024 09:37:31 +0100 Subject: [PATCH] Update style versions --- .pre-commit-config.yaml | 8 +++--- src/_ert_job_runner/reporting/__init__.py | 1 + src/_ert_job_runner/util/data.py | 1 + src/clib/CMakeLists.txt | 10 ++++--- src/ert/__init__.py | 1 + src/ert/analysis/_es_update.py | 26 +++++++++---------- src/ert/config/ensemble_config.py | 8 +++--- src/ert/config/ert_config.py | 22 +++++++++------- src/ert/config/observations.py | 12 +++++---- src/ert/config/parsing/observations_parser.py | 4 +-- src/ert/config/response_config.py | 3 +-- src/ert/config/workflow_job.py | 8 +++--- src/ert/constant_filenames.py | 1 + src/ert/data/_measured_data.py | 1 + .../ensemble_evaluator/_builder/_legacy.py | 3 +-- src/ert/gui/main.py | 8 +++--- .../simulation/ensemble_experiment_panel.py | 8 +++--- .../gui/simulation/ensemble_smoother_panel.py | 8 +++--- .../iterated_ensemble_smoother_panel.py | 8 +++--- .../multiple_data_assimilation_panel.py | 8 +++--- src/ert/job_queue/queue.py | 1 + src/ert/shared/_doc_utils/ert_jobs.py | 6 ++--- src/ert/storage/__init__.py | 6 ++--- src/ert/validation/rangestring.py | 1 + .../test_observation_times.py | 1 + .../config/config_dict_generator.py | 12 ++++----- tests/unit_tests/config/summary_generator.py | 1 + 27 files changed, 100 insertions(+), 77 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6e738100f9..e94a9ebc2c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,25 +9,25 @@ repos: exclude: test-data/eclipse/parse/ERROR.PRT # exact format is needed for testing - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 + rev: v0.1.14 hooks: - id: ruff args: [ --fix ] - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.1.0 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.5 + rev: v17.0.6 hooks: - id: clang-format args: [ --style=file, --Werror] exclude: .json - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.10 + rev: v0.6.13 hooks: - id: cmake-format - id: cmake-lint diff --git a/src/_ert_job_runner/reporting/__init__.py b/src/_ert_job_runner/reporting/__init__.py index 5ca15a74d3d..95d858ae312 100644 --- a/src/_ert_job_runner/reporting/__init__.py +++ b/src/_ert_job_runner/reporting/__init__.py @@ -2,6 +2,7 @@ The reporting package provides classes for reporting the results of forward model jobs. """ + from .base import Reporter from .event import Event from .file import File diff --git a/src/_ert_job_runner/util/data.py b/src/_ert_job_runner/util/data.py index a6bb27fcbd7..9899f41b997 100644 --- a/src/_ert_job_runner/util/data.py +++ b/src/_ert_job_runner/util/data.py @@ -1,4 +1,5 @@ """Utility to compensate for a weak job type.""" + import time from _ert_job_runner.reporting.message import _JOB_STATUS_WAITING diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 13801d18a3b..09a945e5d25 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -66,14 +66,16 @@ list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}") execute_process( COMMAND "${_python_executable}" -c "import resdata; print(resdata.get_include())" - OUTPUT_VARIABLE ECL_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE - COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL LAST) + OUTPUT_VARIABLE ECL_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL + LAST) execute_process( COMMAND "${_python_executable}" -c "import resdata; print(resdata.ResdataPrototype.lib._name)" - OUTPUT_VARIABLE ECL_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO - STDOUT COMMAND_ERROR_IS_FATAL LAST) + OUTPUT_VARIABLE ECL_LIBRARY + OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL + LAST) add_library(resdata SHARED IMPORTED GLOBAL) set_target_properties(resdata PROPERTIES IMPORTED_LOCATION "${ECL_LIBRARY}" diff --git a/src/ert/__init__.py b/src/ert/__init__.py index f1962936ddd..48ec1457581 100644 --- a/src/ert/__init__.py +++ b/src/ert/__init__.py @@ -1,6 +1,7 @@ """ Ert - Ensemble Reservoir Tool - a package for reservoir modeling. """ + from .config import ErtScript from .data import MeasuredData from .job_queue import JobStatus diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 2fd4aaa4972..37067509b48 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -671,16 +671,16 @@ def analysis_ES( start = time.time() for param_batch_idx in TimedIterator(batches, progress_callback): X_local = temp_storage[param_group.name][param_batch_idx, :] - temp_storage[param_group.name][ - param_batch_idx, : - ] = smoother_adaptive_es.assimilate( - X=X_local, - Y=S, - D=D, - alpha=1.0, # The user is responsible for scaling observation covariance (esmda usage) - correlation_threshold=module.correlation_threshold, - cov_YY=cov_YY, - verbose=False, + temp_storage[param_group.name][param_batch_idx, :] = ( + smoother_adaptive_es.assimilate( + X=X_local, + Y=S, + D=D, + alpha=1.0, # The user is responsible for scaling observation covariance (esmda usage) + correlation_threshold=module.correlation_threshold, + cov_YY=cov_YY, + verbose=False, + ) ) _logger.info( f"Adaptive Localization of {param_group} completed in {(time.time() - start) / 60} minutes" @@ -837,9 +837,9 @@ def analysis_IES( ) if active_parameter_indices := param_group.index_list: X = temp_storage[param_group.name][active_parameter_indices, :] - temp_storage[param_group.name][ - active_parameter_indices, : - ] = X + X @ sies_smoother.W / np.sqrt(len(iens_active_index) - 1) + temp_storage[param_group.name][active_parameter_indices, :] = ( + X + X @ sies_smoother.W / np.sqrt(len(iens_active_index) - 1) + ) else: X = temp_storage[param_group.name] temp_storage[param_group.name] = X + X @ sies_smoother.W / np.sqrt( diff --git a/src/ert/config/ensemble_config.py b/src/ert/config/ensemble_config.py index bef4448ce07..ada80e16437 100644 --- a/src/ert/config/ensemble_config.py +++ b/src/ert/config/ensemble_config.py @@ -194,9 +194,11 @@ def make_field(field_list: List[str]) -> Field: surface_list=[SurfaceConfig.from_config_list(s) for s in surface_list], summary_config=summary_config, field_list=[make_field(f) for f in field_list], - refcase=Refcase(start_date, refcase_keys, time_map, data) - if data is not None - else None, + refcase=( + Refcase(start_date, refcase_keys, time_map, data) + if data is not None + else None + ), ) def _node_info(self, object_type: Type[Any]) -> str: diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index 7136e2fa191..65d57811542 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -435,12 +435,10 @@ def __init__(self, job): ) @overload - def substitute(self, string: str) -> str: - ... + def substitute(self, string: str) -> str: ... @overload - def substitute(self, string: None) -> None: - ... + def substitute(self, string: None) -> None: ... def substitute(self, string): if string is None: @@ -500,12 +498,16 @@ def handle_default(job: ForwardModel, arg: str) -> str: "target_file": substituter.substitute(job.target_file), "error_file": substituter.substitute(job.error_file), "start_file": substituter.substitute(job.start_file), - "stdout": substituter.substitute(job.stdout_file) + f".{idx}" - if job.stdout_file - else None, - "stderr": substituter.substitute(job.stderr_file) + f".{idx}" - if job.stderr_file - else None, + "stdout": ( + substituter.substitute(job.stdout_file) + f".{idx}" + if job.stdout_file + else None + ), + "stderr": ( + substituter.substitute(job.stderr_file) + f".{idx}" + if job.stderr_file + else None + ), "stdin": substituter.substitute(job.stdin_file), "argList": [ handle_default(job, substituter.substitute(arg)) diff --git a/src/ert/config/observations.py b/src/ert/config/observations.py index 84cce3bc79c..7e7db7e62b5 100644 --- a/src/ert/config/observations.py +++ b/src/ert/config/observations.py @@ -443,11 +443,13 @@ def _handle_general_observation( { restart: cls._create_gen_obs( ( - general_observation["VALUE"], - general_observation["ERROR"], - ) - if "VALUE" in general_observation - else None, + ( + general_observation["VALUE"], + general_observation["ERROR"], + ) + if "VALUE" in general_observation + else None + ), general_observation.get("OBS_FILE"), indices, ), diff --git a/src/ert/config/parsing/observations_parser.py b/src/ert/config/parsing/observations_parser.py index abe372ae425..26f1b3a59d2 100644 --- a/src/ert/config/parsing/observations_parser.py +++ b/src/ert/config/parsing/observations_parser.py @@ -107,9 +107,7 @@ def parse(filename: str) -> ConfContent: ) -def _parse_content( - content: str, filename: str -) -> List[ +def _parse_content(content: str, filename: str) -> List[ Union[ SimpleHistoryDeclaration, Tuple[ObservationType, FileContextToken, Dict[FileContextToken, Any]], diff --git a/src/ert/config/response_config.py b/src/ert/config/response_config.py index 6ebf3660191..97f27be0d0d 100644 --- a/src/ert/config/response_config.py +++ b/src/ert/config/response_config.py @@ -12,8 +12,7 @@ class ResponseConfig(ABC): name: str @abstractmethod - def read_from_file(self, run_path: str, iens: int) -> xr.Dataset: - ... + def read_from_file(self, run_path: str, iens: int) -> xr.Dataset: ... def to_dict(self) -> Dict[str, Any]: data = dataclasses.asdict(self, dict_factory=CustomDict) diff --git a/src/ert/config/workflow_job.py b/src/ert/config/workflow_job.py index a95b955f42a..d7930354d49 100644 --- a/src/ert/config/workflow_job.py +++ b/src/ert/config/workflow_job.py @@ -87,9 +87,11 @@ def from_file(cls, config_file: str, name: Optional[str] = None) -> "WorkflowJob max_args=content_dict.get("MAX_ARG"), # type: ignore arg_types=arg_types_list, executable=content_dict.get("EXECUTABLE"), # type: ignore - script=str(content_dict.get("SCRIPT")) # type: ignore - if "SCRIPT" in content_dict - else None, + script=( + str(content_dict.get("SCRIPT")) # type: ignore + if "SCRIPT" in content_dict + else None + ), stop_on_fail=content_dict.get("STOP_ON_FAIL"), # type: ignore ) diff --git a/src/ert/constant_filenames.py b/src/ert/constant_filenames.py index bda29a7065f..1a6846913c3 100644 --- a/src/ert/constant_filenames.py +++ b/src/ert/constant_filenames.py @@ -2,6 +2,7 @@ Contains constant definitions of file names used by ert. """ + CERT_FILE = ".ee.pem" JOBS_FILE = "jobs.json" LOG_file = "JOB_LOG" diff --git a/src/ert/data/_measured_data.py b/src/ert/data/_measured_data.py index ebfc4f67d88..7de22b2db07 100644 --- a/src/ert/data/_measured_data.py +++ b/src/ert/data/_measured_data.py @@ -5,6 +5,7 @@ instead of having to implement analysis-functionality into ERT using C/C++. The API is typically meant used as part of workflows. """ + from __future__ import annotations from datetime import datetime diff --git a/src/ert/ensemble_evaluator/_builder/_legacy.py b/src/ert/ensemble_evaluator/_builder/_legacy.py index f05343faf1e..45329a10ebf 100644 --- a/src/ert/ensemble_evaluator/_builder/_legacy.py +++ b/src/ert/ensemble_evaluator/_builder/_legacy.py @@ -42,8 +42,7 @@ class _KillAllJobs(Protocol): - def kill_all_jobs(self) -> None: - ... + def kill_all_jobs(self) -> None: ... class LegacyEnsemble(Ensemble): diff --git a/src/ert/gui/main.py b/src/ert/gui/main.py index 87d26cf6a73..07b505f8763 100755 --- a/src/ert/gui/main.py +++ b/src/ert/gui/main.py @@ -130,9 +130,11 @@ def _start_initial_gui_window( config_warnings, deprecations, None, - plugin_manager.get_help_links() - if plugin_manager is not None - else {}, + ( + plugin_manager.get_help_links() + if plugin_manager is not None + else {} + ), ), None, None, diff --git a/src/ert/gui/simulation/ensemble_experiment_panel.py b/src/ert/gui/simulation/ensemble_experiment_panel.py index 9085052c684..0dc3c4db9ea 100644 --- a/src/ert/gui/simulation/ensemble_experiment_panel.py +++ b/src/ert/gui/simulation/ensemble_experiment_panel.py @@ -79,9 +79,11 @@ def getSimulationArguments(self): current_case=self.notifier.current_case_name, iter_num=int(self._iter_field.text()), realizations=self._active_realizations_field.text(), - experiment_name=self._name_field.text() - if self._name_field.text() != "" - else self._name_field.placeholderText(), + experiment_name=( + self._name_field.text() + if self._name_field.text() != "" + else self._name_field.placeholderText() + ), ) def _realizations_from_fs(self): diff --git a/src/ert/gui/simulation/ensemble_smoother_panel.py b/src/ert/gui/simulation/ensemble_smoother_panel.py index da7412f91f7..169c2be6652 100644 --- a/src/ert/gui/simulation/ensemble_smoother_panel.py +++ b/src/ert/gui/simulation/ensemble_smoother_panel.py @@ -98,8 +98,10 @@ def getSimulationArguments(self) -> Arguments: current_case=self._case_format_model.getValue() % 0, target_case=self._case_format_model.getValue() % 1, realizations=self._active_realizations_field.text(), - experiment_name=self._name_field.text() - if self._name_field.text() != "" - else self._name_field.placeholderText(), + experiment_name=( + self._name_field.text() + if self._name_field.text() != "" + else self._name_field.placeholderText() + ), ) return arguments diff --git a/src/ert/gui/simulation/iterated_ensemble_smoother_panel.py b/src/ert/gui/simulation/iterated_ensemble_smoother_panel.py index a191c0345b7..d07d6f0d645 100644 --- a/src/ert/gui/simulation/iterated_ensemble_smoother_panel.py +++ b/src/ert/gui/simulation/iterated_ensemble_smoother_panel.py @@ -116,7 +116,9 @@ def getSimulationArguments(self): target_case=self._iterated_target_case_format_model.getValue(), realizations=self._active_realizations_field.text(), num_iterations=self._num_iterations_spinner.value(), - experiment_name=self._name_field.text() - if self._name_field.text() != "" - else self._name_field.placeholderText(), + experiment_name=( + self._name_field.text() + if self._name_field.text() != "" + else self._name_field.placeholderText() + ), ) diff --git a/src/ert/gui/simulation/multiple_data_assimilation_panel.py b/src/ert/gui/simulation/multiple_data_assimilation_panel.py index 12b4495551a..225eeb45565 100644 --- a/src/ert/gui/simulation/multiple_data_assimilation_panel.py +++ b/src/ert/gui/simulation/multiple_data_assimilation_panel.py @@ -170,9 +170,11 @@ def getSimulationArguments(self): weights=self.weights, restart_run=self._restart_box.isChecked(), prior_ensemble=self._case_selector.currentText(), - experiment_name=self._name_field.text() - if self._name_field.text() != "" - else self._name_field.placeholderText(), + experiment_name=( + self._name_field.text() + if self._name_field.text() != "" + else self._name_field.placeholderText() + ), ) def setWeights(self, weights): diff --git a/src/ert/job_queue/queue.py b/src/ert/job_queue/queue.py index 918cfbb5adb..ddbcf4c4422 100644 --- a/src/ert/job_queue/queue.py +++ b/src/ert/job_queue/queue.py @@ -2,6 +2,7 @@ Module implementing a queue for managing external jobs. """ + from __future__ import annotations import asyncio diff --git a/src/ert/shared/_doc_utils/ert_jobs.py b/src/ert/shared/_doc_utils/ert_jobs.py index 20cc3ac75ef..e81a7392fa2 100644 --- a/src/ert/shared/_doc_utils/ert_jobs.py +++ b/src/ert/shared/_doc_utils/ert_jobs.py @@ -123,9 +123,9 @@ class _ErtDocumentation(SphinxDirective): def _divide_into_categories( jobs: Dict[str, JobDoc], ) -> Dict[str, Dict[str, List[_ForwardModelDocumentation]]]: - categories: Dict[ - str, Dict[str, List[_ForwardModelDocumentation]] - ] = defaultdict(lambda: defaultdict(list)) + categories: Dict[str, Dict[str, List[_ForwardModelDocumentation]]] = ( + defaultdict(lambda: defaultdict(list)) + ) for job_name, docs in jobs.items(): # Job names in ERT traditionally used upper case letters # for the names of the job. However, at some point duplicate diff --git a/src/ert/storage/__init__.py b/src/ert/storage/__init__.py index db15df69319..9b21c175070 100644 --- a/src/ert/storage/__init__.py +++ b/src/ert/storage/__init__.py @@ -24,15 +24,13 @@ @overload def open_storage( path: Union[str, os.PathLike[str]], mode: Literal["r"] = "r" -) -> StorageReader: - ... +) -> StorageReader: ... @overload def open_storage( path: Union[str, os.PathLike[str]], mode: Literal["w"] -) -> StorageAccessor: - ... +) -> StorageAccessor: ... def open_storage( diff --git a/src/ert/validation/rangestring.py b/src/ert/validation/rangestring.py index 2a07d773135..0cbacc706ac 100644 --- a/src/ert/validation/rangestring.py +++ b/src/ert/validation/rangestring.py @@ -6,6 +6,7 @@ The ranges can overlap. The end of each range is inclusive. """ + from typing import Collection, List, Optional, Union diff --git a/tests/integration_tests/test_observation_times.py b/tests/integration_tests/test_observation_times.py index a83718e8c6c..f832a190a0d 100644 --- a/tests/integration_tests/test_observation_times.py +++ b/tests/integration_tests/test_observation_times.py @@ -1,6 +1,7 @@ """ Tests behavior of matching response times to observation times """ + from contextlib import redirect_stderr from datetime import date, datetime, timedelta from io import StringIO diff --git a/tests/unit_tests/config/config_dict_generator.py b/tests/unit_tests/config/config_dict_generator.py index 929b239bfd2..ab880f92299 100644 --- a/tests/unit_tests/config/config_dict_generator.py +++ b/tests/unit_tests/config/config_dict_generator.py @@ -269,9 +269,9 @@ def to_config_dict(self, config_file, cwd, all_defines=True): ConfigKeys.STD_CUTOFF: self.std_cutoff, ConfigKeys.MAX_RUNTIME: self.max_runtime, ConfigKeys.MIN_REALIZATIONS: self.min_realizations, - ConfigKeys.DEFINE: self.all_defines(config_file, cwd) - if all_defines - else self.define, + ConfigKeys.DEFINE: ( + self.all_defines(config_file, cwd) if all_defines else self.define + ), ConfigKeys.STOP_LONG_RUNNING: self.stop_long_running, ConfigKeys.DATA_KW: self.data_kw_key, ConfigKeys.DATA_FILE: self.data_file, @@ -432,9 +432,9 @@ def ert_config_values(draw, use_eclbase=booleans): data_file=st.just(draw(file_names) + ".DATA"), grid_file=st.just(draw(words) + ".EGRID"), job_script=st.just(draw(file_names) + "job_script"), - jobname=st.just("JOBNAME-" + draw(words)) - if not use_eclbase - else st.just(None), + jobname=( + st.just("JOBNAME-" + draw(words)) if not use_eclbase else st.just(None) + ), runpath=st.just("runpath-" + draw(format_runpath_file_name)), enspath=st.just(draw(words) + ".enspath"), time_map=st.builds(lambda fn: fn + ".timemap", file_names), diff --git a/tests/unit_tests/config/summary_generator.py b/tests/unit_tests/config/summary_generator.py index 9dfbabebd80..90b5fd22eff 100644 --- a/tests/unit_tests/config/summary_generator.py +++ b/tests/unit_tests/config/summary_generator.py @@ -3,6 +3,7 @@ (.SMSPEC and .UNSMRY) without any optional fields. See https://opm-project.org/?page_id=955 """ + from dataclasses import astuple, dataclass from datetime import datetime, timedelta from enum import Enum, unique