11import argparse
22import sys
3- import os
43from importlib import resources
5- import pickle
64
75from compass .setup import setup_cases
8- from compass .io import symlink
96from compass .clean import clean_cases
107
118
@@ -43,12 +40,6 @@ def setup_suite(mpas_core, suite_name, config_file=None, machine=None,
4340 The relative or absolute path to the root of a branch where the MPAS
4441 model has been built
4542 """
46- if machine is None and 'COMPASS_MACHINE' in os .environ :
47- machine = os .environ ['COMPASS_MACHINE' ]
48-
49- if config_file is None and machine is None :
50- raise ValueError ('At least one of config_file and machine is needed.' )
51-
5243 text = resources .read_text ('compass.{}.suites' .format (mpas_core ),
5344 '{}.txt' .format (suite_name ))
5445 tests = list ()
@@ -58,33 +49,9 @@ def setup_suite(mpas_core, suite_name, config_file=None, machine=None,
5849 and not test .startswith ('#' )):
5950 tests .append (test )
6051
61- if work_dir is None :
62- work_dir = os .getcwd ()
63- work_dir = os .path .abspath (work_dir )
64-
65- test_cases = setup_cases (tests , config_file = config_file , machine = machine ,
66- work_dir = work_dir , baseline_dir = baseline_dir ,
67- mpas_model_path = mpas_model_path )
68-
69- test_suite = {'name' : suite_name ,
70- 'test_cases' : test_cases ,
71- 'work_dir' : work_dir }
72-
73- # pickle the test or step dictionary for use at runtime
74- pickle_file = os .path .join (test_suite ['work_dir' ],
75- '{}.pickle' .format (suite_name ))
76- with open (pickle_file , 'wb' ) as handle :
77- pickle .dump (test_suite , handle , protocol = pickle .HIGHEST_PROTOCOL )
78-
79- if 'LOAD_COMPASS_ENV' in os .environ :
80- script_filename = os .environ ['LOAD_COMPASS_ENV' ]
81- # make a symlink to the script for loading the compass conda env.
82- symlink (script_filename , os .path .join (work_dir , 'load_compass_env.sh' ))
83-
84- max_cores , max_of_min_cores = _get_required_cores (test_cases )
85-
86- print ('target cores: {}' .format (max_cores ))
87- print ('minimum cores: {}' .format (max_of_min_cores ))
52+ setup_cases (tests , config_file = config_file , machine = machine ,
53+ work_dir = work_dir , baseline_dir = baseline_dir ,
54+ mpas_model_path = mpas_model_path , suite_name = suite_name )
8855
8956
9057def clean_suite (mpas_core , suite_name , work_dir = None ):
@@ -111,19 +78,7 @@ def clean_suite(mpas_core, suite_name, work_dir=None):
11178 tests = [test .strip () for test in text .split ('\n ' ) if
11279 len (test .strip ()) > 0 and not test .startswith ('#' )]
11380
114- if work_dir is None :
115- work_dir = os .getcwd ()
116- work_dir = os .path .abspath (work_dir )
117-
118- clean_cases (tests = tests , work_dir = work_dir )
119-
120- # delete the pickle file
121- pickle_file = os .path .join (work_dir , '{}.pickle' .format (suite_name ))
122-
123- try :
124- os .remove (pickle_file )
125- except OSError :
126- pass
81+ clean_cases (tests = tests , work_dir = work_dir , suite_name = suite_name )
12782
12883
12984def main ():
@@ -173,16 +128,3 @@ def main():
173128 config_file = args .config_file , machine = args .machine ,
174129 work_dir = args .work_dir , baseline_dir = args .baseline_dir ,
175130 mpas_model_path = args .mpas_model )
176-
177-
178- def _get_required_cores (test_cases ):
179- """ Get the maximum number of target cores and the max of min cores """
180-
181- max_cores = 0
182- max_of_min_cores = 0
183- for test_case in test_cases .values ():
184- for step in test_case .steps .values ():
185- max_cores = max (max_cores , step .cores )
186- max_of_min_cores = max (max_of_min_cores , step .min_cores )
187-
188- return max_cores , max_of_min_cores
0 commit comments