@@ -12,7 +12,7 @@ import subprocess
12
12
import logging
13
13
14
14
from cam_config import ConfigCAM # CAM's configure structure
15
- from atm_musica_config import MUSICA_CCPP_SCHEME_NAME
15
+ from atm_musica_config import MUSICA_CCPP_SCHEME_NAME , MUSICA_CONFIG_DIR_NAME
16
16
from atm_musica_config import MUSICA_REPO_URL , MUSICA_TAG
17
17
from atm_musica_config import CHEMISTRY_DATA_REPO_URL , CHEMISTRY_DATA_TAG
18
18
@@ -176,21 +176,22 @@ def _build_cam():
176
176
# If MUSICA-CCPP scheme is used in a suite, download
177
177
# the MUSICA configuration and build the MUSICA library
178
178
if MUSICA_CCPP_SCHEME_NAME in scheme_names :
179
- _download_musica_configuration (caseroot )
179
+ _ = _download_musica_configuration (caseroot )
180
180
musica_install_path = _build_musica (caseroot )
181
181
182
182
cam_linked_libs = case .get_value ("CAM_LINKED_LIBS" )
183
183
musica_libs = "-lmusica-fortran -lmusica -lyaml-cpp"
184
184
if not musica_libs in cam_linked_libs :
185
185
_set_musica_lib_path (musica_install_path , caseroot )
186
186
187
- cmd += ' USER_INCLDIR="' \
188
- f'-I{ os .path .join (musica_install_path , "include" , "micm" )} ' \
189
- f'-I{ os .path .join (musica_install_path , "include" , "musica" )} ' \
190
- f'-I{ os .path .join (musica_install_path , "include" , "musica" , "micm" )} ' \
191
- f'-I{ os .path .join (musica_install_path , "include" , "musica" , "tuvx" )} ' \
192
- f'-I{ os .path .join (musica_install_path , "include" , "musica" , "fortran" )} ' \
187
+ cmd += ( ' USER_INCLDIR="'
188
+ f'-I{ os .path .join (musica_install_path , "include" , "micm" )} '
189
+ f'-I{ os .path .join (musica_install_path , "include" , "musica" )} '
190
+ f'-I{ os .path .join (musica_install_path , "include" , "musica" , "micm" )} '
191
+ f'-I{ os .path .join (musica_install_path , "include" , "musica" , "tuvx" )} '
192
+ f'-I{ os .path .join (musica_install_path , "include" , "musica" , "fortran" )} '
193
193
'"'
194
+ )
194
195
195
196
retcode , out , err = run_cmd (cmd )
196
197
_LOGGER .info ("Command %s:\n \n stdout:\n %s\n \n stderr:\n %s\n " , cmd , out , err )
@@ -284,8 +285,8 @@ def _build_musica(clone_dest: str) -> str:
284
285
subprocess .run (command , cwd = bld_path , stdout = subprocess .PIPE ,
285
286
stderr = subprocess .PIPE , text = True , check = False )
286
287
except subprocess .CalledProcessError as e :
287
- raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
288
- for cmake to configure the MUSICA CMake project failed." ) from e
288
+ raise subprocess .CalledProcessError (e .returncode , e .cmd ,
289
+ "The subprocess for cmake to configure the MUSICA CMake project failed." ) from e
289
290
except FileNotFoundError as e :
290
291
raise FileNotFoundError ("The 'cmake' command was not found." ) from e
291
292
except OSError as e :
@@ -294,10 +295,10 @@ def _build_musica(clone_dest: str) -> str:
294
295
command = ["cmake" , "--build" , "." , "--target" , "install" ]
295
296
try :
296
297
subprocess .run (command , cwd = bld_path , stdout = subprocess .PIPE ,
297
- stderr = subprocess . PIPE , text = True , check = False )
298
+ text = True , check = False )
298
299
except subprocess .CalledProcessError as e :
299
- raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
300
- for cmake to build the MUSICA library failed." ) from e
300
+ raise subprocess .CalledProcessError (e .returncode , e .cmd ,
301
+ "The subprocess for cmake to build the MUSICA library failed." ) from e
301
302
except FileNotFoundError as e :
302
303
raise FileNotFoundError ("The 'cmake' command was not found." ) from e
303
304
except OSError as e :
@@ -308,7 +309,7 @@ def _build_musica(clone_dest: str) -> str:
308
309
return musica_install_path
309
310
310
311
###############################################################################
311
- def _download_musica_configuration (download_dest : str ) -> None :
312
+ def _download_musica_configuration (download_dest : str ) -> str :
312
313
###############################################################################
313
314
"""
314
315
Downloads the MUSICA configuration and renames the configuration
@@ -321,13 +322,14 @@ def _download_musica_configuration(download_dest: str) -> None:
321
322
Exception: If the directory to be renamed is not found or
322
323
any other exceptions occur during the renaming process,
323
324
an exception is raised with the error message.
325
+ Returns:
326
+ musica_config_path: path to the MUSICA configuration directory
324
327
"""
325
- musica_config_dir_name = "musica_configurations"
326
328
327
329
_clone_and_checkout (CHEMISTRY_DATA_REPO_URL , CHEMISTRY_DATA_TAG , download_dest )
328
330
329
331
original_dir = os .path .join (download_dest , "cam-sima-chemistry-data" , "mechanisms" )
330
- renamed_dir = os .path .join (download_dest , "cam-sima-chemistry-data" , musica_config_dir_name )
332
+ renamed_dir = os .path .join (download_dest , "cam-sima-chemistry-data" , MUSICA_CONFIG_DIR_NAME )
331
333
try :
332
334
os .rename (original_dir , renamed_dir )
333
335
except FileNotFoundError as e :
@@ -339,12 +341,14 @@ def _download_musica_configuration(download_dest: str) -> None:
339
341
except OSError as e :
340
342
raise OSError ("An error occurred while renaming." ) from e
341
343
342
- musica_config_path = os .path .join (download_dest , musica_config_dir_name )
344
+ musica_config_path = os .path .join (download_dest , MUSICA_CONFIG_DIR_NAME )
343
345
if os .path .exists (musica_config_path ):
344
346
shutil .rmtree (musica_config_path )
345
347
346
348
shutil .move (renamed_dir , download_dest )
347
349
350
+ return musica_config_path
351
+
348
352
###############################################################################
349
353
def _set_musica_lib_path (musica_install_path : str , caseroot : str ) -> None :
350
354
###############################################################################
@@ -374,8 +378,8 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
374
378
subprocess .run (command , cwd = caseroot , stdout = subprocess .PIPE ,
375
379
stderr = subprocess .PIPE , text = True , check = False )
376
380
except subprocess .CalledProcessError as e :
377
- raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
378
- for xmlchange to set the MUSICA library path failed." ) from e
381
+ raise subprocess .CalledProcessError (e .returncode , e .cmd ,
382
+ "The subprocess for xmlchange to set the MUSICA library path failed." ) from e
379
383
except FileNotFoundError as e :
380
384
raise FileNotFoundError ("The 'xmlchange' command was not found." ) from e
381
385
except OSError as e :
@@ -408,8 +412,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
408
412
subprocess .run (["git" , "clone" , repo_url , repo_path ],
409
413
stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
410
414
except subprocess .CalledProcessError as e :
411
- raise subprocess .CalledProcessError (e .returncode , e .cmd , f"The subprocess \
412
- for git to clone the repository { repo_url } failed." ) from e
415
+ raise subprocess .CalledProcessError (e .returncode , e .cmd ,
416
+ f"The subprocess for git to clone the repository { repo_url } failed." ) from e
413
417
except FileNotFoundError as e :
414
418
raise FileNotFoundError ("The 'git' command was not found." ) from e
415
419
except OSError as e :
@@ -419,8 +423,8 @@ def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
419
423
subprocess .run (["git" , "-C" , repo_path , "checkout" , tag_name ],
420
424
stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True , check = False )
421
425
except subprocess .CalledProcessError as e :
422
- raise subprocess .CalledProcessError (e .returncode , e .cmd , f"The subprocess \
423
- for git to checkout the branch { tag_name } failed." ) from e
426
+ raise subprocess .CalledProcessError (e .returncode , e .cmd ,
427
+ f"The subprocess for git to checkout the branch { tag_name } failed." ) from e
424
428
except FileNotFoundError as e :
425
429
raise FileNotFoundError ("The 'git' command was not found." ) from e
426
430
except OSError as e :
0 commit comments