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 _install_and_cache_venv(session: nox.sessions.Session) -> None: """ Cache the nox session environment. This consists of saving a hexdigest (sha256) of the associated Conda lock file. Parameters ---------- session: object A `nox.sessions.Session` object. """ lockfile = _session_lockfile(session) session.conda_install(f"--file={lockfile}") with _session_cachefile(session).open("w") as cachefile: cachefile.write(_file_content(lockfile))
def tests(session: nox.sessions.Session): """ Perform esmf-regrid integration and unit tests. Parameters ---------- session: object A `nox.sessions.Session` object. """ _prepare_env(session) # Install the esmf-regrid source in develop mode. session.install("--no-deps", "--editable", ".") if COVERAGE: # Execute the tests with code coverage. session.conda_install("--channel=conda-forge", *COVERAGE_PACKAGES) session.run("pytest", "--cov-report=xml", "--cov") session.run("codecov") else: # Execute the tests. session.run("pytest")