File tree 2 files changed +17
-12
lines changed
2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -225,21 +225,15 @@ def create_run_path(
225
225
run_path = Path (run_arg .runpath )
226
226
if run_arg .active :
227
227
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 :
229
232
target_file = substitutions .substitute_real_iter (
230
233
target_file , run_arg .iens , ensemble .iteration
231
234
)
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
-
241
235
result = substitutions .substitute_real_iter (
242
- file_content ,
236
+ source_file_content ,
243
237
run_arg .iens ,
244
238
ensemble .iteration ,
245
239
)
Original file line number Diff line number Diff line change @@ -273,8 +273,19 @@ def parameter_info(self) -> dict[str, Any]:
273
273
@cached_property
274
274
def templates_configuration (self ) -> list [tuple [str , str ]]:
275
275
try :
276
+ templates : list [tuple [str , str ]] = []
276
277
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
278
289
except (FileNotFoundError , json .JSONDecodeError ):
279
290
pass
280
291
# If the file is missing or broken, we return an empty list
You can’t perform that action at this time.
0 commit comments