Skip to content

Commit

Permalink
Add ability to install conda requirements from a yml file.
Browse files Browse the repository at this point in the history
A fair bit of this code is taken from wntrblm/nox#260 (comment)
  • Loading branch information
kuchtact committed Aug 8, 2024
1 parent 8dcad2e commit ced26b4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pathlib import Path

import nox
from yaml import safe_load

supported_python_versions = ("3.9", "3.10", "3.11", "3.12")
maxpython = max(supported_python_versions)
Expand All @@ -8,11 +11,22 @@
# because it has excellent performance when resolving requirements.
nox.options.default_venv_backend = "conda|uv|virtualenv"

# Load in the conda environment file.
environment = safe_load(Path("mamba_environment.yml").read_text())
channels = environment.get("channels")
conda = environment.get("dependencies")
requirements = conda.pop(-1).get("pip")


def install_environment(session):
session.conda_install(*conda, channel=channels, silent=False)
session.install(*requirements)


@nox.session(python=supported_python_versions)
@nox.session(python=supported_python_versions, venv_backend="mamba")
def tests(session):
"""Run tests with pytest."""
session.install(".")
install_environment(session)
session.run("pytest")


Expand Down

0 comments on commit ced26b4

Please sign in to comment.