Пример #1
0
def _check_conda():
    conda_path = _get_conda_bin_executable("conda")
    try:
        run(conda_path, "--help", stream_output=False)
    except Exception as exc_info:
        raise Exception(
            "Could not find Conda executable at {0}. "
            "Ensure Conda is installed as per the instructions "
            "at https://docs.conda.io/projects/conda/en/latest/user-guide/install/"
        ) from exc_info
Пример #2
0
    def execute(self,
                command: str,
                cwd: str = None,
                stream_output: bool = True):
        if self.use_current_env:
            _logger.info(
                'use_current_env flag = True. Start to execute command without changing environment'
            )
            exit_code, output, err_ = run('bash',
                                          '-c',
                                          command,
                                          cwd=cwd,
                                          stream_output=stream_output)
        else:
            _logger.info(
                f'use_current_env flag = False. Start to execute command in {self.exec_env}'
            )
            exit_code, output, err_ = self.exec_env.execute(
                command, cwd=cwd, stream_output=stream_output)

        _logger.info(
            'Subprocess result: %s\n\nSTDOUT:\n%s\n\nSTDERR:%s\n ======' %
            (exit_code, output, err_))

        return output
Пример #3
0
    def create_env(self):
        env_id = self._name
        conda_exec = _get_conda_bin_executable('conda')

        if self.env_created():
            _logger.info(
                f'Conda env with name {env_id!r} already exists. Creating step is skipped'
            )
        else:
            _logger.info(f'Creating conda env with name {env_id!r}')
            run(conda_exec,
                'create',
                '--yes',
                '--name',
                env_id,
                stream_output=False)
Пример #4
0
    def install_dependencies(self):

        env_id = self._name
        conda_exec = _get_conda_bin_executable('conda')

        # Install requirements from dep. list
        conda_dep_list = os.path.join(self._manifest_path,
                                      self.binaries.conda_path)
        _logger.info(
            f'Installing mandatory requirements from {conda_dep_list} to {env_id!r}'
        )
        run(conda_exec,
            'env',
            'update',
            f'--name={env_id}',
            f'--file={conda_dep_list}',
            stream_output=False)
Пример #5
0
 def execute(self,
             command: str,
             cwd: str = None,
             stream_output: bool = True):
     activate_cmd = _get_activate_conda_command(self._name)
     _logger.info(f'cwd: {cwd}')
     return run('bash',
                '-c',
                f'{activate_cmd} && {command}',
                cwd=cwd,
                stream_output=False)
Пример #6
0
 def env_created(self):
     conda_exec = _get_conda_bin_executable('conda')
     _1, stdout, _2 = run(conda_exec,
                          'env',
                          'list',
                          '--json',
                          stream_output=False)
     env_names = [
         os.path.basename(env) for env in json.loads(stdout)['envs']
     ]
     return self._name in env_names