def create(self) -> bool: """Create the virtualenv or venv.""" if not self._clean_location(): logger.debug( "Re-using existing virtual environment at {}.".format( self.location_name ) ) return False if self.venv_or_virtualenv == "virtualenv": cmd = [sys.executable, "-m", "virtualenv", self.location] if self.interpreter: cmd.extend(["-p", self._resolved_interpreter]) else: cmd = [self._resolved_interpreter, "-m", "venv", self.location] cmd.extend(self.venv_params) logger.info( "Creating virtual environment ({}) using {} in {}".format( self.venv_or_virtualenv, os.path.basename(self._resolved_interpreter), self.location_name, ) ) nox.command.run(cmd, silent=True, log=False) return True
def create(self) -> bool: """Create the conda env.""" if not self._clean_location(): logger.debug( "Re-using existing conda env at {}.".format(self.location_name) ) return False cmd = [ "conda", "create", "--yes", "--prefix", self.location, # Ensure the pip package is installed. "pip", ] cmd.extend(self.venv_params) if self.interpreter: python_dep = "python={}".format(self.interpreter) else: python_dep = "python" cmd.append(python_dep) logger.info( "Creating conda env in {} with {}".format(self.location_name, python_dep) ) nox.command.run(cmd, silent=True, log=False) return True
def create(self) -> bool: """Create the virtualenv or venv.""" if not self._clean_location(): logger.debug( f"Re-using existing virtual environment at {self.location_name}." ) self._reused = True return False if self.venv_or_virtualenv == "virtualenv": cmd = [sys.executable, "-m", "virtualenv", self.location] if self.interpreter: cmd.extend(["-p", self._resolved_interpreter]) else: cmd = [self._resolved_interpreter, "-m", "venv", self.location] cmd.extend(self.venv_params) resolved_interpreter_name = os.path.basename( self._resolved_interpreter) logger.info( f"Creating virtual environment ({self.venv_or_virtualenv}) using" f" {resolved_interpreter_name} in {self.location_name}") nox.command.run(cmd, silent=True, log=nox.options.verbose or False) return True
def create(self) -> bool: """Create the conda env.""" if not self._clean_location(): logger.debug( f"Re-using existing conda env at {self.location_name}.") self._reused = True return False cmd = [self.conda_cmd, "create", "--yes", "--prefix", self.location] cmd.extend(self.venv_params) # Ensure the pip package is installed. cmd.append("pip") if self.interpreter: python_dep = f"python={self.interpreter}" else: python_dep = "python" cmd.append(python_dep) logger.info( f"Creating conda env in {self.location_name} with {python_dep}") nox.command.run(cmd, silent=True, log=nox.options.verbose or False) return True
def create(self): """Create the virtualenv.""" if not self._clean_location(): logger.debug('Re-using existing virtualenv.') return cmd = ['virtualenv', self.location] if self.interpreter: cmd.extend(['-p', self.interpreter]) self.run(cmd, in_venv=False)
def run(self): if self.debug: logger.debug(str(self)) else: logger.info(str(self)) try: self.func(*self.args, **self.kwargs) return True except Exception as e: logger.exception('Function {} raised {}.'.format( self._func_name, e)) raise CommandFailed(e)
def create(self): """Create the virtualenv.""" if not self._clean_location(): logger.debug( 'Re-using existing virtualenv at {}.'.format(self.location)) return False cmd = ['virtualenv', self.location] if self.interpreter: cmd.extend(['-p', self._resolved_interpreter]) self.run(cmd, in_venv=False) return True
def _run_commands(self): env = self.venv.env.copy() env.update(self.config.env) for command in self.config._commands: if isinstance(command, Command): command(path_override=self.venv.bin, env_fallback=env) elif isinstance(command, InstallCommand): if not self._should_install_deps: logger.debug( 'Skipping installation of "{}".'.format(command)) continue else: command(self.venv) else: command()
def create(self): """Create the virtualenv.""" if not self._clean_location(): logger.debug("Re-using existing virtualenv at {}.".format( self.location_name)) return False cmd = [sys.executable, "-m", "virtualenv", self.location] if self.interpreter: cmd.extend(["-p", self._resolved_interpreter]) logger.info("Creating virtualenv using {} in {}".format( os.path.basename(self._resolved_interpreter), self.location)) nox.command.run(cmd, silent=True, log=False) return True
def create(self): """Create the virtualenv.""" if not self._clean_location(): logger.debug("Re-using existing virtualenv at {}.".format(self.location)) return False cmd = [sys.executable, "-m", "virtualenv", self.location] if self.interpreter: cmd.extend(["-p", self._resolved_interpreter]) logger.info( "Creating virtualenv using {} in {}".format( os.path.basename(self._resolved_interpreter), self.location ) ) nox.command.run(cmd, silent=True, log=False) return True
def prepare_venv(session: nox.sessions.Session) -> None: """ Create and cache the nox session conda environment, and additionally provide conda environment package details and info. Note that, iris is installed into the environment using pip. Parameters ---------- session: object A `nox.sessions.Session` object. Notes ----- See - https://github.com/theacodes/nox/issues/346 - https://github.com/theacodes/nox/issues/260 """ lockfile = session_lockfile(session) venv_dir = session.virtualenv.location_name if not venv_populated(session): # environment has been created but packages not yet installed # populate the environment from the lockfile logger.debug(f"Populating conda env at {venv_dir}") session.conda_install("--file", str(lockfile)) cache_venv(session) elif venv_changed(session): # destroy the environment and rebuild it logger.debug(f"Lockfile changed. Re-creating conda env at {venv_dir}") _re_orig = session.virtualenv.reuse_existing session.virtualenv.reuse_existing = False session.virtualenv.create() session.conda_install("--file", str(lockfile)) session.virtualenv.reuse_existing = _re_orig cache_venv(session) logger.debug(f"Environment {venv_dir} up to date") cache_cartopy(session) # Determine whether verbose diagnostics have been requested # from the command line. verbose = "-v" in session.posargs or "--verbose" in session.posargs if verbose: session.run("conda", "info") session.run("conda", "list", f"--prefix={venv_dir}") session.run( "conda", "list", f"--prefix={venv_dir}", "--explicit", )
def _prepare_env(session: nox.sessions.Session) -> None: lockfile = _session_lockfile(session) venv_dir = session.virtualenv.location_name if not _venv_populated(session): # Environment has been created but packages not yet installed. # Populate the environment from the lockfile. logger.debug(f"Populating conda env: {venv_dir}") session.conda_install(f"--file={lockfile}") _cache_venv(session) elif _venv_changed(session): # Destroy the environment and rebuild it. logger.debug(f"Lockfile changed. Recreating conda env: {venv_dir}") _reuse_original = session.virtualenv.reuse_existing session.virtualenv.reuse_existing = False session.virtualenv.create() session.conda_install(f"--file={lockfile}") session.virtualenv.reuse_existing = _reuse_original _cache_venv(session) logger.debug(f"Environment up to date: {venv_dir}") iris_artifact = _get_iris_github_artifact(session) if iris_artifact: # Install the iris source in develop mode. tmp_dir = Path(session.create_tmp()) iris_dir = tmp_dir / "iris" cwd = Path.cwd() if not iris_dir.is_dir(): session.run_always("git", "clone", IRIS_GITHUB, str(iris_dir), external=True) session.cd(str(iris_dir)) session.run_always("git", "fetch", "origin", external=True) session.run_always("git", "checkout", iris_artifact, external=True) session.cd(str(cwd)) session.install("--no-deps", "--editable", str(iris_dir)) # Determine whether verbose diagnostics have been requested # from the command line. verbose = "-v" in session.posargs or "--verbose" in session.posargs if verbose: session.run_always("conda", "info") session.run_always("conda", "list", f"--prefix={venv_dir}") session.run_always( "conda", "list", f"--prefix={venv_dir}", "--explicit", )
def debug(self, *args: Any, **kwargs: Any) -> None: """Outputs a debug-level message during the session.""" logger.debug(*args, **kwargs)