Skip to content

Optionally add links to load_compass_env.sh in test cases #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions testing_and_setup/compass/setup_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import textwrap
import netCDF4
import shutil
import errno

try:
from collections import defaultdict
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -1549,6 +1552,24 @@ def get_case_name(config_file): # {{{

return name
# }}}

def link_load_compass_env(init_path, configs): # {{{

if configs.getboolean('conda', 'link_load_compass'):
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:
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
# }}}
# }}}


Expand Down Expand Up @@ -1590,6 +1611,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 <core>/load_compass_env.sh is "
"included with each test case")

args = parser.parse_args()

Expand Down Expand Up @@ -1678,6 +1703,15 @@ 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')

# Build variables for history output
old_dir = os.getcwd()
os.chdir(config.get('script_paths', 'script_path'))
Expand Down