def test_fillTemplateFile_basic(self): """Basic test of fill_template_file""" template_path = os.path.join(self._testdir, 'template.txt') final_path = os.path.join(self._testdir, 'final.txt') template_contents = """\ Hello $foo Goodbye $bar """ with open(template_path, 'w') as f: f.write(template_contents) fillins = {'foo': 'aardvark', 'bar': 'zyzzyva'} fill_template_file(template_path, final_path, fillins) expected_final_text = """\ Hello aardvark Goodbye zyzzyva """ with open(final_path) as f: final_contents = f.read() self.assertEqual(final_contents, expected_final_text)
def _stage_runtime_inputs(build_dir, no_pnetcdf): """Stage CTSM and LILAC runtime inputs Args: build_dir (str): path to build directory no_pnetcdf (bool): if True, use netcdf rather than pnetcdf """ os.makedirs(os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME)) inputdata_dir = _xmlquery('DIN_LOC_ROOT', build_dir) fill_template_file(path_to_template=os.path.join(_PATH_TO_TEMPLATES, 'ctsm_template.cfg'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'ctsm.cfg'), substitutions={'INPUTDATA': inputdata_dir}) fill_template_file(path_to_template=os.path.join(_PATH_TO_TEMPLATES, 'lilac_in_template'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'lilac_in'), substitutions={'INPUTDATA': inputdata_dir}) pio_stride = _xmlquery('MAX_MPITASKS_PER_NODE', build_dir) if no_pnetcdf: pio_typename = 'netcdf' # pio_rearranger = 1 is generally more efficient with netcdf (see # https://github.com/ESMCI/cime/pull/3732#discussion_r508954806 and the following # discussion) pio_rearranger = 1 else: pio_typename = 'pnetcdf' pio_rearranger = 2 fill_template_file(path_to_template=os.path.join( _PATH_TO_TEMPLATES, 'lnd_modelio_template.nml'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'lnd_modelio.nml'), substitutions={ 'PIO_REARRANGER': pio_rearranger, 'PIO_STRIDE': pio_stride, 'PIO_TYPENAME': pio_typename }) shutil.copyfile(src=os.path.join(path_to_ctsm_root(), 'cime_config', 'usermods_dirs', 'lilac', 'user_nl_ctsm'), dst=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'user_nl_ctsm')) make_link( _PATH_TO_MAKE_RUNTIME_INPUTS, os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'make_runtime_inputs')) make_link( _PATH_TO_DOWNLOAD_INPUT_DATA, os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'download_input_data'))
def _stage_runtime_inputs(build_dir, no_pnetcdf): """Stage CTSM and LILAC runtime inputs Args: build_dir (str): path to build directory no_pnetcdf (bool): if True, use netcdf rather than pnetcdf """ os.makedirs(os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME)) inputdata_dir = _xmlquery('DIN_LOC_ROOT', build_dir) fill_template_file(path_to_template=os.path.join(_PATH_TO_TEMPLATES, 'ctsm_template.cfg'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'ctsm.cfg'), substitutions={'INPUTDATA': inputdata_dir}) fill_template_file(path_to_template=os.path.join(_PATH_TO_TEMPLATES, 'lilac_in_template'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'lilac_in'), substitutions={'INPUTDATA': inputdata_dir}) pio_stride = _xmlquery('MAX_MPITASKS_PER_NODE', build_dir) if no_pnetcdf: pio_typename = 'netcdf' else: pio_typename = 'pnetcdf' fill_template_file(path_to_template=os.path.join( _PATH_TO_TEMPLATES, 'lnd_modelio_template.nml'), path_to_final=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'lnd_modelio.nml'), substitutions={ 'PIO_STRIDE': pio_stride, 'PIO_TYPENAME': pio_typename }) shutil.copyfile(src=os.path.join(path_to_ctsm_root(), 'cime_config', 'usermods_dirs', 'lilac', 'user_nl_ctsm'), dst=os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'user_nl_ctsm')) make_link( _PATH_TO_MAKE_RUNTIME_INPUTS, os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'make_runtime_inputs')) make_link( _PATH_TO_DOWNLOAD_INPUT_DATA, os.path.join(build_dir, _RUNTIME_INPUTS_DIRNAME, 'download_input_data'))
def _fill_out_machine_files(build_dir, os_type, compiler, netcdf_path, esmf_lib_path, max_mpitasks_per_node, gmake, gmake_j, pnetcdf_path=None, pio_filesystem_hints=None, gptl_nano_timers=False, extra_fflags='', extra_cflags=''): """Fill out the machine porting templates for this machine / compiler For documentation of args, see the documentation in the build_ctsm function """ os.makedirs(os.path.join(build_dir, _MACHINE_CONFIG_DIRNAME)) # ------------------------------------------------------------------------ # Fill in config_machines.xml # ------------------------------------------------------------------------ fill_template_file(path_to_template=os.path.join( _PATH_TO_TEMPLATES, 'config_machines_template.xml'), path_to_final=os.path.join(build_dir, _MACHINE_CONFIG_DIRNAME, 'config_machines.xml'), substitutions={ 'OS': os_type, 'COMPILER': compiler, 'CIME_OUTPUT_ROOT': build_dir, 'GMAKE': gmake, 'GMAKE_J': gmake_j, 'MAX_MPITASKS_PER_NODE': max_mpitasks_per_node }) # ------------------------------------------------------------------------ # Fill in config_compilers.xml # ------------------------------------------------------------------------ if gptl_nano_timers: gptl_cppdefs = _GPTL_NANOTIMERS_CPPDEFS else: gptl_cppdefs = '' if pio_filesystem_hints: pio_filesystem_hints_tag = '<PIO_FILESYSTEM_HINTS>{}</PIO_FILESYSTEM_HINTS>'.format( pio_filesystem_hints) else: pio_filesystem_hints_tag = '' if pnetcdf_path: pnetcdf_path_tag = '<PNETCDF_PATH>{}</PNETCDF_PATH>'.format( pnetcdf_path) else: pnetcdf_path_tag = '' fill_template_file(path_to_template=os.path.join( _PATH_TO_TEMPLATES, 'config_compilers_template.xml'), path_to_final=os.path.join(build_dir, _MACHINE_CONFIG_DIRNAME, 'config_compilers.xml'), substitutions={ 'COMPILER': compiler, 'GPTL_CPPDEFS': gptl_cppdefs, 'NETCDF_PATH': netcdf_path, 'PIO_FILESYSTEM_HINTS': pio_filesystem_hints_tag, 'PNETCDF_PATH': pnetcdf_path_tag, 'ESMF_LIBDIR': esmf_lib_path, 'EXTRA_CFLAGS': extra_cflags, 'EXTRA_FFLAGS': extra_fflags })