From d08ef9cb601f51b403c312959f93628a2a1cf4de Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Fri, 20 Mar 2020 16:24:33 +0100 Subject: [PATCH 1/2] Optionally add links to load_compass_env.sh in test cases This is specified either in the config file or at the command line. --- testing_and_setup/compass/setup_testcase.py | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/testing_and_setup/compass/setup_testcase.py b/testing_and_setup/compass/setup_testcase.py index a4553301e6..99b6922629 100755 --- a/testing_and_setup/compass/setup_testcase.py +++ b/testing_and_setup/compass/setup_testcase.py @@ -26,6 +26,7 @@ import textwrap import netCDF4 import shutil +import errno try: from collections import defaultdict @@ -517,6 +518,8 @@ def generate_driver_scripts(config_file, configs): # {{{ if not os.path.exists(init_path): os.makedirs(init_path) + link_load_compass_env(init_path, configs) + # Create script file script = open('{}/{}'.format(init_path, name), 'w') @@ -1549,6 +1552,22 @@ def get_case_name(config_file): # {{{ return name # }}} + +def link_load_compass_env(init_path, configs): # {{{ + + if configs.getboolean('conda', 'link_load_compass'): + target = configs.get('conda', 'load_compass_script') + + link_name = '{}/load_compass_env.sh'.format(init_path) + try: + os.symlink(target, link_name) + except OSError as e: + if e.errno == errno.EEXIST: + os.remove(link_name) + os.symlink(target, link_name) + else: + raise e +# }}} # }}} @@ -1590,6 +1609,10 @@ def get_case_name(config_file): # {{{ help="If set, script will create case directories in " "work_dir rather than the current directory.", metavar="PATH") + parser.add_argument("--link_load_compass", dest="link_load_compass", + action="store_true", + help="If set, a link to load_compass_env.sh is included" + " with each test case") args = parser.parse_args() @@ -1678,6 +1701,20 @@ def get_case_name(config_file): # {{{ config.set('script_input_arguments', 'model_runtime', args.model_runtime) + if not config.has_section('conda'): + config.add_section('conda') + + if not config.has_option('conda', 'link_load_compass'): + config.set('conda', 'link_load_compass', 'False') + + if args.link_load_compass: + config.set('conda', 'link_load_compass', 'True') + + if config.getboolean('conda', 'link_load_compass'): + load_script = '{}/load_compass_env.sh'.format( + os.path.dirname(os.path.abspath(__file__))) + config.set('conda', 'load_compass_script', load_script) + # Build variables for history output old_dir = os.getcwd() os.chdir(config.get('script_paths', 'script_path')) From 3a389760f7559714a84b20bcdd52c426a561544e Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Wed, 1 Jul 2020 02:23:31 -0600 Subject: [PATCH 2/2] Link load_compass_env.sh from the core directory This will allow different cores to be synced with different versions of the compass conda environment and will allow each core to update the version its develop branch as needed. --- testing_and_setup/compass/setup_testcase.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/testing_and_setup/compass/setup_testcase.py b/testing_and_setup/compass/setup_testcase.py index 99b6922629..ed3538d707 100755 --- a/testing_and_setup/compass/setup_testcase.py +++ b/testing_and_setup/compass/setup_testcase.py @@ -1556,7 +1556,9 @@ def get_case_name(config_file): # {{{ def link_load_compass_env(init_path, configs): # {{{ if configs.getboolean('conda', 'link_load_compass'): - target = configs.get('conda', 'load_compass_script') + target = '{}/{}/load_compass_env.sh'.format( + configs.get('script_paths', 'script_path'), + configs.get('script_paths', 'core_dir')) link_name = '{}/load_compass_env.sh'.format(init_path) try: @@ -1611,8 +1613,8 @@ def link_load_compass_env(init_path, configs): # {{{ metavar="PATH") parser.add_argument("--link_load_compass", dest="link_load_compass", action="store_true", - help="If set, a link to load_compass_env.sh is included" - " with each test case") + help="If set, a link to /load_compass_env.sh is " + "included with each test case") args = parser.parse_args() @@ -1710,11 +1712,6 @@ def link_load_compass_env(init_path, configs): # {{{ if args.link_load_compass: config.set('conda', 'link_load_compass', 'True') - if config.getboolean('conda', 'link_load_compass'): - load_script = '{}/load_compass_env.sh'.format( - os.path.dirname(os.path.abspath(__file__))) - config.set('conda', 'load_compass_script', load_script) - # Build variables for history output old_dir = os.getcwd() os.chdir(config.get('script_paths', 'script_path'))