Skip to content

Commit

Permalink
ci: Use uv in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Mar 4, 2024
1 parent dd866a0 commit a06e3e3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .github/actions/install-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ runs:
run: |
pipx install nox
nox --version
- name: Install uv
shell: bash
env:
PIP_CONSTRAINT: ${{ inputs.constraints }}
run: |
pipx install uv
uv --version
3 changes: 2 additions & 1 deletion .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
griffe==0.41.0
nox==2023.4.22
nox==2024.3.2
pip==24.0
pip-tools==7.4.0
uv==0.1.14
72 changes: 37 additions & 35 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import shutil
from pathlib import Path

from nox import Session, session
import nox

GH_ACTIONS_ENV_VAR = "GITHUB_ACTIONS"
FORCE_COLOR = "FORCE_COLOR"

nox.options.default_venv_backend = "uv"

package = "citric"

python_versions = ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8"]
Expand All @@ -23,7 +25,7 @@
locations = "src", "tests", "noxfile.py", "docs/conf.py"


def _run_tests(session: Session, *args: str) -> None:
def _run_tests(session: nox.Session, *args: str) -> None:
env = {"COVERAGE_CORE": "sysmon"}
try:
session.run("coverage", "run", "-m", "pytest", *args, env=env)
Expand All @@ -32,24 +34,24 @@ def _run_tests(session: Session, *args: str) -> None:
session.notify("coverage", posargs=[])


@session(python=all_python_versions, tags=["test"])
def tests(session: Session) -> None:
@nox.session(python=all_python_versions, tags=["test"])
def tests(session: nox.Session) -> None:
"""Execute pytest tests and compute coverage."""
session.install(".[tests]")
session.install("-v", "citric[tests] @ .")
args = session.posargs or ["-m", "not integration_test"]
_run_tests(session, *args)


@session(python=[main_cpython_version, main_pypy_version], tags=["test"])
def integration(session: Session) -> None:
@nox.session(python=[main_cpython_version, main_pypy_version], tags=["test"])
def integration(session: nox.Session) -> None:
"""Execute integration tests and compute coverage."""
session.install(".[tests]")
session.install("-v", "citric[tests] @ .")
args = session.posargs or ["-m", "integration_test"]
_run_tests(session, *args)


@session(python=[main_cpython_version, main_pypy_version], tags=["test"])
def xdoctest(session: Session) -> None:
@nox.session(python=[main_cpython_version, main_pypy_version], tags=["test"])
def xdoctest(session: nox.Session) -> None:
"""Run examples with xdoctest."""
if session.posargs:
args = [package, *session.posargs]
Expand All @@ -58,48 +60,48 @@ def xdoctest(session: Session) -> None:
if FORCE_COLOR in os.environ:
args.append("--colored=1")

session.install(".")
session.install("xdoctest[colors]")
session.install("-v", "citric @ .")
session.install("-v", "xdoctest[colors]")
session.run("python", "-m", "xdoctest", *args)


@session()
def coverage(session: Session) -> None:
@nox.session()
def coverage(session: nox.Session) -> None:
"""Upload coverage data."""
args = session.posargs or ["report"]

session.install("coverage[toml]")
session.install("-v", "coverage[toml]")

if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine", "--debug=pathmap")

session.run("coverage", *args)


@session(name="deps", python=python_versions)
def dependencies(session: Session) -> None:
@nox.session(name="deps", python=python_versions)
def dependencies(session: nox.Session) -> None:
"""Check issues with dependencies."""
session.install(".[dev]")
session.install("deptry")
session.install("-v", "citric[dev] @ .")
session.install("-v", "deptry")
session.run("deptry", "src", "tests", "docs")


@session(python=python_versions, tags=["lint"])
def mypy(session: Session) -> None:
@nox.session(python=python_versions, tags=["lint"])
def mypy(session: nox.Session) -> None:
"""Type-check using mypy."""
args = session.posargs or locations
session.install(".[typing]")
session.install("-v", "citric[typing] @ .")
session.run("mypy", *args)


@session(name="docs-build")
def docs_build(session: Session) -> None:
@nox.session(name="docs-build")
def docs_build(session: nox.Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "build"]
if not session.posargs and FORCE_COLOR in os.environ:
args.insert(0, "--color")

session.install(".[docs]")
session.install("-v", "citric[docs] @ .")

build_dir = Path("build")
if build_dir.exists():
Expand All @@ -108,8 +110,8 @@ def docs_build(session: Session) -> None:
session.run("sphinx-build", *args)


@session(name="docs-serve")
def docs_serve(session: Session) -> None:
@nox.session(name="docs-serve")
def docs_serve(session: nox.Session) -> None:
"""Build the documentation."""
args = session.posargs or [
"--open-browser",
Expand All @@ -122,7 +124,7 @@ def docs_serve(session: Session) -> None:
"docs",
"build",
]
session.install(".[docs]")
session.install("-v", "citric[docs] @ .")

build_dir = Path("build")
if build_dir.exists():
Expand All @@ -131,8 +133,8 @@ def docs_serve(session: Session) -> None:
session.run("sphinx-autobuild", *args)


@session(name="api")
def api_changes(session: Session) -> None:
@nox.session(name="api")
def api_changes(session: nox.Session) -> None:
"""Check for API changes."""
args = [
"griffe",
Expand All @@ -147,8 +149,8 @@ def api_changes(session: Session) -> None:
session.run(*args, external=True)


@session(python=["3.11"])
def notebook(session: Session) -> None:
@nox.session(python=["3.11"])
def notebook(session: nox.Session) -> None:
"""Start a Jupyter notebook."""
session.install(
"boto3",
Expand All @@ -174,8 +176,8 @@ def notebook(session: Session) -> None:
)


@session(name="generate-tags", tags=["status"])
def tags(session: Session) -> None:
@nox.session(name="generate-tags", tags=["status"])
def tags(session: nox.Session) -> None:
"""Print tags."""
session.install("requests", "requests-cache")
session.install("-v", "requests", "requests-cache")
session.run("python", "scripts/docker_tags.py")

0 comments on commit a06e3e3

Please sign in to comment.