def _create_build_metadata_for_component(config_dir, libroot, bldroot, case): ############################################################################### """ Ensure that crucial Filepath and CIME_CPPDEFS files exist for this component. In many cases, the bld/configure script will have already created these. """ bc_path = os.path.join(config_dir, "buildlib_cmake") expect(os.path.exists(bc_path), "Missing: {}".format(bc_path)) buildlib = import_from_file("buildlib_cmake", os.path.join(config_dir, "buildlib_cmake")) cmake_args = buildlib.buildlib(bldroot, libroot, case) return "" if cmake_args is None else cmake_args
def test_import_from_file(self): with tempfile.NamedTemporaryFile() as fd: fd.writelines([ b"def test():\n", b" return 'value'", ]) fd.flush() module = import_from_file("test.py", fd.name) assert module.test() == "value"
def test_case_submit_interface(self): # the current directory may not exist, so make sure we are in a real directory os.chdir(os.getenv("HOME")) sys.path.append(self.TOOLS_DIR) case_submit_path = os.path.join(self.TOOLS_DIR, "case.submit") module = utils.import_from_file("case.submit", case_submit_path) sys.argv = [ "case.submit", "--batch-args", "'random_arguments_here.%j'", "--mail-type", "fail", "--mail-user", "'random_arguments_here.%j'", ] module._main_func(None, True)
If that function is NOT defined in the component's buildnml, then we return the given default_nlfile. """ # Check if buildnml is present in the expected location, and if so, whether it # contains the function "get_user_nl_list"; if so, we'll import the module and call # that function; if not, we'll fall back on the default value. buildnml_path = os.path.join(model_dir, "buildnml") has_function = False if os.path.isfile(buildnml_path) and file_contains_python_function( buildnml_path, "get_user_nl_list"): has_function = True if has_function: comp_buildnml = import_from_file("comp_buildnml", buildnml_path) return comp_buildnml.get_user_nl_list(case) else: return [default_nlfile] ############################################################################### def _create_macros_cmake(caseroot, cmake_macros_dir, mach_obj, compiler, case_cmake_path): ############################################################################### if not os.path.isfile(os.path.join(caseroot, "Macros.cmake")): safe_copy(os.path.join(cmake_macros_dir, "Macros.cmake"), caseroot) if not os.path.exists(os.path.join(caseroot, "cmake_macros")): shutil.copytree(cmake_macros_dir, case_cmake_path) copy_depends_files(mach_obj.get_machine_name(), mach_obj.machines_dir,