Skip to content

Commit

Permalink
Run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Oct 5, 2024
1 parent 329b324 commit 8976973
Show file tree
Hide file tree
Showing 61 changed files with 482 additions and 301 deletions.
16 changes: 10 additions & 6 deletions src/_ert/forward_model_runner/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,12 @@ def _get_processtree_data(
oom_score = int(
Path(f"/proc/{process.pid}/oom_score").read_text(encoding="utf-8")
)
with contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
), process.oneshot():
with (
contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
),
process.oneshot(),
):
memory_rss = process.memory_info().rss
cpu_seconds = process.cpu_times().user

Expand All @@ -402,9 +405,10 @@ def _get_processtree_data(
if oom_score is not None
else oom_score_child
)
with contextlib.suppress(
NoSuchProcess, AccessDenied, ZombieProcess
), child.oneshot():
with (
contextlib.suppress(NoSuchProcess, AccessDenied, ZombieProcess),
child.oneshot(),
):
memory_rss += child.memory_info().rss
cpu_seconds += child.cpu_times().user
return (memory_rss, cpu_seconds, oom_score)
2 changes: 2 additions & 0 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def _get_observations_and_responses(
list(observations_and_responses["report_step"].data)
* len(observations_and_responses["index"].data),
observations_and_responses["index"].data,
strict=False,
)
]
)
Expand Down Expand Up @@ -351,6 +352,7 @@ def _load_observations_and_responses(
ens_mean_mask,
ens_std_mask,
indexes,
strict=False,
):
update_snapshot.append(
ObservationAndResponseSnapshot(
Expand Down
6 changes: 4 additions & 2 deletions src/ert/config/gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def __post_init__(self) -> None:
@property
def expected_input_files(self) -> List[str]:
expected_files = []
for input_file, report_steps in zip(self.input_files, self.report_steps_list):
for input_file, report_steps in zip(
self.input_files, self.report_steps_list, strict=False
):
if report_steps is None:
expected_files.append(input_file)
else:
Expand Down Expand Up @@ -130,7 +132,7 @@ def _read_file(filename: Path, report_step: int) -> xr.Dataset:
datasets_per_name = []

for name, input_file, report_steps in zip(
self.keys, self.input_files, self.report_steps_list
self.keys, self.input_files, self.report_steps_list, strict=False
):
datasets_per_report_step = []
if report_steps is None:
Expand Down
6 changes: 4 additions & 2 deletions src/ert/config/gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ def write_to_runpath(
f" is of size {len(self.transform_functions)}, expected {array.size}"
)

data = dict(zip(array["names"].values.tolist(), array.values.tolist()))
data = dict(
zip(array["names"].values.tolist(), array.values.tolist(), strict=False)
)

log10_data = {
tf.name: math.log(data[tf.name], 10)
Expand Down Expand Up @@ -477,7 +479,7 @@ def _parse_transform_function_definition(
f"Unable to convert float number: {p}"
) from e

params = dict(zip(param_names, param_floats))
params = dict(zip(param_names, param_floats, strict=False))

return TransformFunction(
name=t.name,
Expand Down
2 changes: 1 addition & 1 deletion src/ert/config/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _handle_history_observation(
segment_instance,
)
data: Dict[Union[int, datetime], Union[GenObservation, SummaryObservation]] = {}
for date, error, value in zip(refcase.dates, std_dev, values):
for date, error, value in zip(refcase.dates, std_dev, values, strict=False):
data[date] = SummaryObservation(summary_key, summary_key, value, error)

return {
Expand Down
2 changes: 1 addition & 1 deletion src/ert/dark_storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def gen_data_keys(ensemble: Ensemble) -> Iterator[str]:
if gen_data_config:
assert isinstance(gen_data_config, GenDataConfig)
for key, report_steps in zip(
gen_data_config.keys, gen_data_config.report_steps_list
gen_data_config.keys, gen_data_config.report_steps_list, strict=False
):
if report_steps is None:
yield f"{key}@0"
Expand Down
3 changes: 2 additions & 1 deletion src/ert/data/_measured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def _get_data(
index_vals = ds.observations.coords.to_index().droplevel("report_step")

index_vals = [
(name, data_i, i) for i, (name, data_i) in zip(data_index, index_vals)
(name, data_i, i)
for i, (name, data_i) in zip(data_index, index_vals, strict=False)
]
measured_data.append(
pd.DataFrame(
Expand Down
17 changes: 10 additions & 7 deletions src/ert/ensemble_evaluator/_wait_for_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ async def attempt_connection(
) -> None:
timeout = aiohttp.ClientTimeout(connect=connection_timeout)
headers = {} if token is None else {"token": token}
async with aiohttp.ClientSession() as session, session.request(
method="get",
url=url,
ssl=get_ssl_context(cert),
headers=headers,
timeout=timeout,
) as resp:
async with (
aiohttp.ClientSession() as session,
session.request(
method="get",
url=url,
ssl=get_ssl_context(cert),
headers=headers,
timeout=timeout,
) as resp,
):
resp.raise_for_status()


Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/tools/plot/style_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def createLabelLayout(self, layout: Optional[QLayout] = None) -> QLayout:

titles = ["Line style", "Width", "Marker style", "Size"]
sizes = self.getItemSizes()
for title, size in zip(titles, sizes):
for title, size in zip(titles, sizes, strict=False):
label = QLabel(title)
label.setFixedWidth(size)
layout.addWidget(label)
Expand Down
2 changes: 1 addition & 1 deletion src/ert/resources/forward-models/res/script/ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def make_SLURM_machine_list(SLURM_JOB_NODELIST, SLURM_TASKS_PER_NODE):
task_count_list += _expand_SLURM_task_count(task_count_string)

host_list = []
for node, count in zip(nodelist, task_count_list):
for node, count in zip(nodelist, task_count_list, strict=False):
host_list += [node] * count

return host_list
Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_run_arguments(
job_names = runpaths.get_jobnames(range(len(active_realizations)), iteration)

for iens, (run_path, job_name, active) in enumerate(
zip(paths, job_names, active_realizations)
zip(paths, job_names, active_realizations, strict=False)
):
run_args.append(
RunArg(
Expand Down
4 changes: 3 additions & 1 deletion src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ def _create_mask_from_failed_realizations(self) -> List[bool]:
return [
initial and not completed
for initial, completed in zip(
self._initial_realizations_mask, self._completed_realizations_mask
self._initial_realizations_mask,
self._completed_realizations_mask,
strict=False,
)
]
else:
Expand Down
4 changes: 3 additions & 1 deletion src/ert/simulator/forward_model_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def try_load(cls, path: str) -> "ForwardModelStatus":
end_time = _deserialize_date(status_data["end_time"])
status = cls(status_data["run_id"], start_time, end_time=end_time)

for fm_step, state in zip(fm_steps_data["jobList"], status_data["jobs"]):
for fm_step, state in zip(
fm_steps_data["jobList"], status_data["jobs"], strict=False
):
status.add_step(ForwardModelStepStatus.load(fm_step, state, path))

return status
Expand Down
4 changes: 3 additions & 1 deletion src/everest/bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def methods_help(cls):
pubmets.remove("methods_help") # Current method should not show up in desc
maxlen = max(len(m) for m in pubmets)
docstrs = [getattr(cls, m).__doc__ for m in pubmets]
doclist = [m.ljust(maxlen + 1) + d for m, d in zip(pubmets, docstrs)]
doclist = [
m.ljust(maxlen + 1) + d for m, d in zip(pubmets, docstrs, strict=False)
]
return "\n".join(doclist)

def run(self, args):
Expand Down
2 changes: 1 addition & 1 deletion src/everest/bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _get_progress_summary(status):
labels = ("Waiting", "Pending", "Running", "Complete", "FAILED")
return " | ".join(
f"{color}{key}: {value}{Fore.RESET}"
for color, key, value in zip(colors, labels, status)
for color, key, value in zip(colors, labels, status, strict=False)
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/everest/jobs/well_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def well_set(well_data_file, new_entry_file, output_file):
)
raise ValueError(err_msg)

for well_entry, data_elem in zip(well_data, entry_data):
for well_entry, data_elem in zip(well_data, entry_data, strict=False):
well_entry[entry_key] = data_elem

with everest.jobs.io.safe_open(output_file, "w") as fout:
Expand Down
1 change: 1 addition & 0 deletions src/everest/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __call__(
for control_name, control_value in zip(
metadata.config.variables.names, # type: ignore
control_values[sim_idx, :],
strict=False,
):
self._add_control(controls, control_name, control_value)
case_data.append((real_id, controls))
Expand Down
2 changes: 1 addition & 1 deletion src/ieverest/widgets/batch_status_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _set_progress(self, progress):
wdg.setFixedSize(self._ICON_SIZE)

# update the buttons
for wdg, info in zip(self._jobs_wdgs, progress):
for wdg, info in zip(self._jobs_wdgs, progress, strict=False):
job_status = get_job_status(info)
icon_name = self._STATUS_ICONS.get(job_status, self._DEFAULT_STATUS_ICON)

Expand Down
2 changes: 1 addition & 1 deletion test-data/ert/snake_oil/jobs/snake_oil_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def writeDiff(filename, vector1, vector2):
with open(filename, "w", encoding="utf-8") as f:
for node1, node2 in zip(vector1, vector2):
for node1, node2 in zip(vector1, vector2, strict=False):
f.write(f"{node1-node2:f}\n")


Expand Down
2 changes: 1 addition & 1 deletion test-data/everest/math_func/jobs/adv_distance3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def compute_distance_squared(p, q):
d = ((i - j) ** 2 for i, j in zip(p, q))
d = ((i - j) ** 2 for i, j in zip(p, q, strict=False))
d = sum(d)
return -d

Expand Down
2 changes: 1 addition & 1 deletion test-data/everest/math_func/jobs/distance3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def compute_distance_squared(p, q):
d = ((i - j) ** 2 for i, j in zip(p, q))
d = ((i - j) ** 2 for i, j in zip(p, q, strict=False))
d = sum(d)
return -d

Expand Down
28 changes: 16 additions & 12 deletions tests/ert/ui_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def test_test_run_on_lsf_configuration_works_with_no_errors(tmp_path):
)
@pytest.mark.usefixtures("copy_poly_case")
def test_that_the_cli_raises_exceptions_when_parameters_are_missing(mode):
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly-no-gen-kw.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly-no-gen-kw.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "GEN_KW" not in line:
fout.write(line)
Expand Down Expand Up @@ -181,9 +182,10 @@ def test_that_the_model_raises_exception_if_active_less_than_minimum_realization
Omit testing of SingleTestRun because that executes with 1 active realization
regardless of configuration.
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_high_min_reals.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_high_min_reals.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "MIN_REALIZATIONS" in line:
fout.write("MIN_REALIZATIONS 100")
Expand Down Expand Up @@ -211,9 +213,10 @@ def test_that_the_model_warns_when_active_realizations_less_min_realizations():
NUM_REALIZATIONS when running ensemble_experiment.
A warning is issued when NUM_REALIZATIONS is higher than active_realizations.
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_lower_active_reals.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_lower_active_reals.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "MIN_REALIZATIONS" in line:
fout.write("MIN_REALIZATIONS 100")
Expand Down Expand Up @@ -861,9 +864,10 @@ def test_that_log_is_cleaned_up_from_repeated_forward_model_steps(caplog):
"""Verify that the run model now gereneates a cleanup log when
there are repeated forward models
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_repeated_forward_model_steps.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_repeated_forward_model_steps.ert", "w", encoding="utf-8") as fout,
):
forward_model_steps = ["FORWARD_MODEL poly_eval\n"] * 5
lines = fin.readlines() + forward_model_steps
fout.writelines(lines)
Expand Down
Loading

0 comments on commit 8976973

Please sign in to comment.