Example #1
0
    def _setup(self) -> None:
        """Used for initial environment creation - mimics parent method where possible."""
        try:
            self.conda = _find_conda()
        except IOError as e:
            raise asv_util.UserError(str(e))
        if find_spec("nox") is None:
            raise asv_util.UserError("Module not found: nox")

        message = f"Creating Nox-Conda environment for {self.name} ."
        log.info(message)

        try:
            self._nox_prep_env(setup=True)
        except Exception:
            raise
        finally:
            # No longer need the setup checkout now that the environment has been built.
            self.project_temp_checkout.cleanup()

        # Create an environment.yml file from the requirements in asv.conf.json.
        # No default dependencies to specify - unlike parent - because Nox
        #  includes these by default.
        conda_args, pip_args = self._get_requirements(self.conda)
        if conda_args or pip_args:
            with self._extra_reqs_path.open("w") as req_file:
                req_file.write(f"name: {self.name}\n")
                req_file.write("channels:\n")
                req_file.writelines(
                    [f"   - {channel}\n" for channel in self._conda_channels])
                req_file.write("dependencies:\n")

                # Categorise and write dependencies based on pip vs. conda.
                req_file.writelines(
                    [f"   - {package}\n" for package in conda_args])
                if pip_args:
                    # And now specify the packages that are to be installed in the
                    # pip subsection.
                    req_file.write("   - pip:\n")
                    req_file.writelines(
                        [f"     - {package}\n" for package in pip_args])
Example #2
0
    def _setup(self) -> None:
        """Used for initial environment creation - mimics parent method where possible."""
        try:
            self.conda = _find_conda()
        except IOError as e:
            raise asv_util.UserError(str(e))
        if find_spec("nox") is None:
            raise asv_util.UserError("Module not found: nox")

        message = f"Creating Nox-Conda environment for {self.name} ."
        log.info(message)

        try:
            self._nox_prep_env(setup=True)
        finally:
            # No longer need the setup checkout now that the environment has been built.
            self.project_temp_checkout.cleanup()

        conda_args, pip_args = self._get_requirements(self.conda)
        if conda_args or pip_args:
            message = (
                "Ignoring user input package requirements. Benchmark "
                "environment management is exclusively performed by Nox.")
            log.warning(message)
Example #3
0
    def _setup(self):
        log.info("Creating oggm conda environment for {0}".format(self.name))

        try:
            conda = _find_conda()
        except IOError as e:
            raise util.UserError(str(e))

        env_file = tempfile.NamedTemporaryFile(mode="w",
                                               delete=False,
                                               suffix=".yml")
        try:
            pyver = str(self._python).replace(".", "")[:2]
            oggm_env = OGGM_CONDA_ENVS[pyver]
            req = requests.get(OGGM_CONDA_ENV_URL.format(oggm_env))
            req.raise_for_status()
            env_text = req.text

            for line in env_text.splitlines():
                if line.startswith("prefix:") or self._has_requirement(line):
                    continue
                elif line.startswith("name:"):
                    env_file.write("name: {0}\n".format(self.name))
                else:
                    env_file.write(line + "\n")

            conda_args, pip_args = self._get_requirements(conda)
            env_file.writelines(('  - %s\n' % s for s in conda_args))
            if pip_args:
                env_file.write('  - pip:\n')
                env_file.writelines(('    - %s\n' % s for s in pip_args))

            env_file.close()

            util.check_output([conda] + [
                'env', 'create', '-f', env_file.name, '-p', self._path,
                '--force'
            ])
        except Exception as exc:
            if os.path.isfile(env_file.name):
                with open(env_file.name, "r") as f:
                    text = f.read()
                log.info(
                    "oggm conda env create failed: in {} with:\n{}".format(
                        self._path, text))
            raise
        finally:
            os.unlink(env_file.name)
Example #4
0
def _multiprocessing_raise_usererror(arg):
    try:
        raise util.UserError("hello")
    except BaseException as exc:
        raise util.ParallelFailure(str(exc), exc.__class__,
                                   traceback.format_exc())
Example #5
0
 def conda_executable(self):
     """Find conda executable."""
     try:
         return _find_conda()
     except IOError as e:
         raise util.UserError(str(e))