Skip to content

Commit c0102f2

Browse files
committed
Provide content of templates directly in templates_configuration
1 parent 828cb8f commit c0102f2

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/ert/enkf_main.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,15 @@ def create_run_path(
225225
run_path = Path(run_arg.runpath)
226226
if run_arg.active:
227227
run_path.mkdir(parents=True, exist_ok=True)
228-
for source_file, target_file in ensemble.experiment.templates_configuration:
228+
for (
229+
source_file_content,
230+
target_file,
231+
) in ensemble.experiment.templates_configuration:
229232
target_file = substitutions.substitute_real_iter(
230233
target_file, run_arg.iens, ensemble.iteration
231234
)
232-
try:
233-
file_content = (
234-
ensemble.experiment.mount_point / source_file
235-
).read_text("utf-8")
236-
except UnicodeDecodeError as e:
237-
raise ValueError(
238-
f"Unsupported non UTF-8 character found in file: {source_file}"
239-
) from e
240-
241235
result = substitutions.substitute_real_iter(
242-
file_content,
236+
source_file_content,
243237
run_arg.iens,
244238
ensemble.iteration,
245239
)

src/ert/storage/local_experiment.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,19 @@ def parameter_info(self) -> dict[str, Any]:
273273
@cached_property
274274
def templates_configuration(self) -> list[tuple[str, str]]:
275275
try:
276+
templates: list[tuple[str, str]] = []
276277
with open(self.mount_point / self._templates_file, encoding="utf-8") as f:
277-
return json.load(f)
278+
templates = json.load(f)
279+
templates_with_content: list[tuple[str, str]] = []
280+
for source_file, target_file in templates:
281+
try:
282+
file_content = (self.mount_point / source_file).read_text("utf-8")
283+
templates_with_content.append((file_content, target_file))
284+
except UnicodeDecodeError as e:
285+
raise ValueError(
286+
f"Unsupported non UTF-8 character found in file: {source_file}"
287+
) from e
288+
return templates_with_content
278289
except (FileNotFoundError, json.JSONDecodeError):
279290
pass
280291
# If the file is missing or broken, we return an empty list

0 commit comments

Comments
 (0)