@@ -283,14 +283,28 @@ def _build_musica(clone_dest: str) -> str:
283
283
"-D MUSICA_BUILD_FORTRAN_INTERFACE=ON" ,
284
284
".."
285
285
]
286
- result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
287
- if result .returncode != 0 :
288
- raise Exception (f"Unable to configure the MUSICA CMake project. Error: { result .stderr } " )
286
+ try :
287
+ subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
288
+ text = True , check = False )
289
+ except subprocess .CalledProcessError as e :
290
+ raise subprocess .CalledProcessError (f"The subprocess for cmake \
291
+ to configure the MUSICA CMake project failed." ) from e
292
+ except FileNotFoundError as e :
293
+ raise FileNotFoundError (f"The 'cmake' command was not found." ) from e
294
+ except OSError as e :
295
+ raise OSError (f"An error occurred while executing the 'cmake' command." ) from e
289
296
290
297
command = ["cmake" , "--build" , "." , "--target" , "install" ]
291
- result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
292
- if result .returncode != 0 :
293
- raise Exception (f"Unable to build the MUSICA library. Error: { result .stderr } " )
298
+ try :
299
+ subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
300
+ text = True , check = False )
301
+ except subprocess .CalledProcessError as e :
302
+ raise subprocess .CalledProcessError (f"The subprocess for cmake \
303
+ to build the MUSICA library failed." ) from e
304
+ except FileNotFoundError as e :
305
+ raise FileNotFoundError (f"The 'cmake' command was not found." ) from e
306
+ except OSError as e :
307
+ raise OSError (f"An error occurred while executing the 'cmake' command." ) from e
294
308
295
309
os .chdir (current_dir )
296
310
musica_install_path = os .path .join (bld_path , install_dir )
@@ -321,13 +335,13 @@ def _download_musica_configuration(download_dest: str) -> None:
321
335
try :
322
336
os .rename (original_dir , renamed_dir )
323
337
except FileNotFoundError as e :
324
- raise FileNotFoundError (f"The directory '{ original_dir } ' was not found. Error: { e } " )
338
+ raise FileNotFoundError (f"The directory '{ original_dir } ' was not found." ) from e
325
339
except FileExistsError as e :
326
- raise FileExistsError (f"The destination directory '{ renamed_dir } ' already exists. Error: { e } " )
340
+ raise FileExistsError (f"The destination directory '{ renamed_dir } ' already exists." ) from e
327
341
except PermissionError as e :
328
- raise PermissionError (f"Permission denied to rename '{ original_dir } '. Error: { e } " )
342
+ raise PermissionError (f"Permission denied to rename '{ original_dir } '." ) from e
329
343
except OSError as e :
330
- raise OSError (f"An error occurred while renaming: { e } " )
344
+ raise OSError (f"An error occurred while renaming." ) from e
331
345
332
346
musica_config_path = os .path .join (download_dest , musica_config_dir_name )
333
347
if os .path .exists (musica_config_path ):
@@ -366,11 +380,11 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
366
380
text = True , check = False )
367
381
except subprocess .CalledProcessError as e :
368
382
raise subprocess .CalledProcessError (f"The subprocess for xmlchange \
369
- to set the MUSICA library path failed with an error.: { e } " )
383
+ to set the MUSICA library path failed." ) from e
370
384
except FileNotFoundError as e :
371
- raise FileNotFoundError (f"The 'xmlchange' command was not found: { e } " )
385
+ raise FileNotFoundError (f"The 'xmlchange' command was not found." ) from e
372
386
except OSError as e :
373
- raise OSError (f"An error occurred while running 'xmlchange' command: { e } " )
387
+ raise OSError (f"An error occurred while executing the 'xmlchange' command." ) from e
374
388
375
389
os .chdir (current_dir )
376
390
@@ -395,17 +409,27 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
395
409
if os .path .exists (repo_path ):
396
410
shutil .rmtree (repo_path )
397
411
398
- result = subprocess .run (["git" , "clone" , repo_url , repo_path ],
399
- stderr = subprocess .PIPE , text = True , check = False )
400
- if result .returncode != 0 :
401
- raise Exception (f"Unable to clone the repository: { repo_url } . \
402
- Error: { result .stderr } " )
403
-
404
- result = subprocess .run (["git" , "-C" , repo_path , "checkout" , tag_name ],
405
- stderr = subprocess .PIPE , text = True , check = False )
406
- if result .returncode != 0 :
407
- raise Exception (f"Unable to checkout the branch: { tag_name } . \
408
- Error: { result .stderr } " )
412
+ try :
413
+ subprocess .run (["git" , "clone" , repo_url , repo_path ],
414
+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
415
+ except subprocess .CalledProcessError as e :
416
+ raise subprocess .CalledProcessError (f"The subprocess for git \
417
+ to clone the repository { repo_url } failed." ) from e
418
+ except FileNotFoundError as e :
419
+ raise FileNotFoundError (f"The 'git' command was not found." ) from e
420
+ except OSError as e :
421
+ raise OSError (f"An error occurred while executing the 'git' command." ) from e
422
+
423
+ try :
424
+ subprocess .run (["git" , "-C" , repo_path , "checkout" , tag_name ],
425
+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
426
+ except subprocess .CalledProcessError as e :
427
+ raise subprocess .CalledProcessError (f"The subprocess for git \
428
+ to checkout the branch { tag_name } failed." ) from e
429
+ except FileNotFoundError as e :
430
+ raise FileNotFoundError (f"The 'git' command was not found." ) from e
431
+ except OSError as e :
432
+ raise OSError (f"An error occurred while executing the 'git' command." ) from e
409
433
410
434
###############################################################################
411
435
0 commit comments