def _check_conda(): from asv.plugins.conda import _conda_lock conda = _find_conda() with _conda_lock(): try: subprocess.check_call([conda, 'build', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except subprocess.CalledProcessError: raise RuntimeError("conda-build is missing")
def _build_project(self, repo, commit_hash, build_dir): # at "build" time, we build the environment from the provided lockfile self.run_executable( _find_conda(), [ "install", "-y", "-p", self._path, "--file", f"{build_dir}/{self._lockfile_path}", ], ) log.info( f"Environment {self.name} updated to spec at {commit_hash[:8]}" ) log.debug( self.run_executable(_find_conda(), ["list", "-p", self._path]) ) return super()._build_project(repo, commit_hash, build_dir)
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)
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])
def _build_dummy_conda_pkg(name, version, build_dir, dst): # Build fake conda packages for testing from asv.plugins.conda import _conda_lock build_dir = os.path.abspath(build_dir) with open(join(build_dir, 'meta.yaml'), 'w') as f: f.write( textwrap.dedent("""\ package: name: "{name}" version: "{version}" source: path: {build_dir} build: number: 0 script: "python -m pip install . --no-deps --ignore-installed " requirements: host: - pip - python run: - python about: license: BSD summary: Dummy test package """.format(name=name, version=version, build_dir=util.shlex_quote(build_dir)))) conda = _find_conda() for pyver in [PYTHON_VER1, PYTHON_VER2]: with _conda_lock(): subprocess.check_call([ conda, 'build', '--output-folder=' + dst, '--no-anaconda-upload', '--python=' + pyver, '.' ], cwd=build_dir)
def _build_dummy_conda_pkg(name, version, build_dir, dst): # Build fake conda packages for testing build_dir = os.path.abspath(build_dir) with open(join(build_dir, 'meta.yaml'), 'w') as f: f.write(textwrap.dedent("""\ package: name: "{name}" version: "{version}" source: path: {build_dir} build: number: 0 script: "python -m pip install . --no-deps --ignore-installed " requirements: host: - pip - python run: - python about: license: BSD summary: Dummy test package """.format(name=name, version=version, build_dir=util.shlex_quote(build_dir)))) conda = _find_conda() for pyver in [PYTHON_VER1, PYTHON_VER2]: subprocess.check_call([conda, 'build', '--output-folder=' + dst, '--no-anaconda-upload', '--python=' + pyver, '.'], cwd=build_dir)
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)
# Installable library versions to use in tests DUMMY1_VERSION = "0.14" DUMMY2_VERSIONS = ["0.3.7", "0.3.9"] WIN = (os.name == "nt") try: util.which('pypy') HAS_PYPY = True except (RuntimeError, IOError): HAS_PYPY = hasattr(sys, 'pypy_version_info') and (sys.version_info[:2] == (2, 7)) try: # Conda can install required Python versions on demand _find_conda() HAS_CONDA = True except (RuntimeError, IOError): HAS_CONDA = False try: import virtualenv HAS_VIRTUALENV = True except ImportError: HAS_VIRTUALENV = False try: util.which('python{}'.format(PYTHON_VER2)) HAS_PYTHON_VER2 = True except (RuntimeError, IOError): HAS_PYTHON_VER2 = False
def _setup(self): # create the shell of a conda environment, that includes no packages log.info("Creating conda environment for {0}".format(self.name)) self.run_executable( _find_conda(), ["create", "-y", "-p", self._path, "--force"] )
def conda_executable(self): """Find conda executable.""" try: return _find_conda() except IOError as e: raise util.UserError(str(e))
DUMMY1_VERSION = "0.14" DUMMY2_VERSIONS = ["0.3.7", "0.3.9"] WIN = (os.name == "nt") try: util.which('pypy') HAS_PYPY = True except (RuntimeError, IOError): HAS_PYPY = hasattr(sys, 'pypy_version_info') and (sys.version_info[:2] == (2, 7)) try: # Conda can install required Python versions on demand _find_conda() HAS_CONDA = True except (RuntimeError, IOError): HAS_CONDA = False try: import virtualenv HAS_VIRTUALENV = True except ImportError: HAS_VIRTUALENV = False try: util.which('python{}'.format(PYTHON_VER2)) HAS_PYTHON_VER2 = True