Beispiel #1
0
 def create_all_environments(self):
     paths = util.PathManager()
     command = '{}/src/conda_env_setup.sh'.format(paths.CODE_ROOT)
     try:
         subprocess.Popen(['bash', '-c', command])
     except OSError as e:
         print('ERROR :', e.errno, e.strerror)
Beispiel #2
0
 def activate_env_command(self, pod):
     # Source conda_init.sh to set things that aren't set b/c we aren't
     # in an interactive shell.
     paths = util.PathManager()
     conda_prefix = os.path.join(self.conda_env_root, pod.env)
     return 'source {}/src/conda_init.sh && conda activate {}'.format(
         paths.CODE_ROOT, conda_prefix)
 def _setup_html(self):
     if os.path.isfile(os.path.join(self.MODEL_WK_DIR, 'index.html')):
         print("WARNING: index.html exists, not re-creating.")
     else:
         paths = util.PathManager()
         html_dir = os.path.join(paths.CODE_ROOT, 'src', 'html')
         shutil.copy2(os.path.join(html_dir, 'mdtf_diag_banner.png'),
                      self.MODEL_WK_DIR)
         shutil.copy2(os.path.join(html_dir, 'mdtf1.html'),
                      os.path.join(self.MODEL_WK_DIR, 'index.html'))
 def _setup_pod(self, pod):
     paths = util.PathManager()
     translate = util.VariableTranslator()
     pod.__dict__.update(paths.modelPaths(self))
     pod.__dict__.update(paths.podPaths(pod))
     for idx, var in enumerate(pod.varlist):
         cf_name = translate.toCF(pod.convention, var['var_name'])
         pod.varlist[idx]['CF_name'] = cf_name
         pod.varlist[idx]['name_in_model'] = translate.fromCF(
             self.convention, cf_name)
         if 'alternates' in pod.varlist[idx]:
             pod.varlist[idx]['alternates'] = [
                 translate.fromCF(self.convention, translate.toCF(pod.convention, var2)) \
                     for var2 in pod.varlist[idx]['alternates']
             ]
Beispiel #5
0
    def __init__(self, config, verbose=0):
        super(CondaEnvironmentManager, self).__init__(config, verbose)

        if ('conda_env_root' in config['settings']) and \
            (os.path.isdir(config['settings']['conda_env_root'])):
            # need to resolve relative path
            cwd = os.getcwd()
            paths = util.PathManager()
            os.chdir(os.path.join(paths.CODE_ROOT, 'src'))
            self.conda_env_root = os.path.realpath(
                config['settings']['conda_env_root'])
            os.chdir(cwd)
        else:
            self.conda_env_root = os.path.join(
                subprocess.check_output('conda info --root', shell=True),
                'envs'  # only true in default install, need to fix
            )
    def __init__(self, case_dict, config={}, verbose=0):
        self.case_name = case_dict['CASENAME']
        self.model_name = case_dict['model']
        self.firstyr = case_dict['FIRSTYR']
        self.lastyr = case_dict['LASTYR']

        if 'variable_convention' in case_dict:
            self.convention = case_dict['variable_convention']
        else:
            self.convention = 'CF'  # default to assuming CF-compliance
        if 'pod_list' in case_dict:
            # run a set of PODs specific to this model
            self.pod_list = case_dict['pod_list']
        else:
            self.pod_list = config['pod_list']  # use global list of PODs
        self.pods = []

        paths = util.PathManager()
        self.__dict__.update(paths.modelPaths(self))
    def __init__(self, pod_name, verbose=0):
        """POD initializer. Given a POD name, we attempt to read a settings.yml 
        file in a subdirectory of ``/diagnostics`` by that name and parse the
        contents.

        Args:
            pod_name (:obj:`str`): Name of the POD to initialize.
            verbose (:obj:`int`, optional): Logging verbosity level. Default 0.
        """
        paths = util.PathManager()

        self.name = pod_name
        self.__dict__.update(paths.podPaths(self))
        file_contents = util.read_yaml(
            os.path.join(self.POD_CODE_DIR, 'settings.yml'))

        config = self._parse_pod_settings(file_contents['settings'], verbose)
        self.__dict__.update(config)
        config = self._parse_pod_varlist(file_contents['varlist'], verbose)
        self.varlist = config
    def validate_command(self):
        """Produces the shell command to validate the POD's runtime environment 
        (ie, check for all requested third-party module dependencies.)

        Called by :meth:`environment_manager.EnvironmentManager.run`. 
        Dependencies are passed as arguments to the shell script 
        ``src/validate_environment.sh``, which is invoked in the POD's subprocess
        before the POD is run.

        Returns:
            (:obj:`str`) Command-line invocation to validate the POD's runtime environment.
        """
        paths = util.PathManager()
        command_path = os.path.join(paths.CODE_ROOT, 'src',
                                    'validate_environment.sh')
        command = [
            command_path, ' -v', ' -p '.join([''] + self.required_programs),
            ' -z '.join([''] + self.pod_env_vars.keys()),
            ' -a '.join([''] + self.required_python_modules),
            ' -b '.join([''] + self.required_ncl_scripts),
            ' -c '.join([''] + self.required_r_packages)
        ]
        return ''.join(command)
Beispiel #9
0
    def _call_conda_create(self, env_name):
        paths = util.PathManager()
        prefix = '_MDTF-diagnostics'
        if env_name == prefix:
            short_name = 'base'
        else:
            short_name = env_name[(len(prefix) + 1):]
        path = '{}/src/conda_env_{}.yml'.format(paths.CODE_ROOT, short_name)
        if not os.path.exists(path):
            print "Can't find {}".format(path)
        else:
            conda_prefix = os.path.join(self.conda_env_root, env_name)
            print 'Creating conda env {} in {}'.format(env_name, conda_prefix)

        commands = \
            'source {}/src/conda_init.sh && '.format(paths.CODE_ROOT) \
                + 'conda env create --force -q -p="{}" -f="{}"'.format(
                conda_prefix, path
            )
        try:
            subprocess.Popen(['bash', '-c', commands])
        except OSError as e:
            print('ERROR :', e.errno, e.strerror)