-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnoxfile.py
More file actions
143 lines (115 loc) · 4.07 KB
/
noxfile.py
File metadata and controls
143 lines (115 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os
from pathlib import Path
import nox
# Default Nox behavior
nox.options.default_venv_backend = "uv|virtualenv"
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["pre-commit", "unit"]
# Environment variables for consistent runs
PROJECT_ENV = {
"PYTHONIOENCODING": "utf-8",
"MPLBACKEND": "Agg", # avoids GUI issues with matplotlib
}
VENV_DIR = Path("./venv").resolve()
def set_env(session, env_dict):
"""Helper: apply environment variables to session."""
for key, value in env_dict.items():
session.env[key] = value
@nox.session(name="unit")
def run_unit(session):
"""Run unit tests."""
set_env(session, PROJECT_ENV)
session.install("-e", ".[all,dev]", silent=False) # editable + dev deps
session.run("pytest", "-m", "unit")
@nox.session(name="integration")
def run_integration(session):
"""Run integration tests."""
set_env(session, PROJECT_ENV)
session.install("-e", ".[all,dev]", silent=False) # editable + dev deps
session.run("pytest", "-m", "integration", success_codes=[0, 5])
@nox.session(name="coverage")
def run_coverage(session):
"""Run tests with coverage tracking."""
set_env(session, PROJECT_ENV)
session.install("coverage", "pytest-cov", silent=False)
session.install("-e", ".[all,dev]", silent=False)
session.run(
"pytest",
"-m",
"unit or integration",
"--cov=modularml",
"--cov-report=xml",
"tests/",
)
@nox.session(name="examples")
def run_examples(session):
"""Run Jupyter notebook examples with nbmake."""
set_env(session, PROJECT_ENV)
session.install("-e", ".[all,dev]", "nbmake", silent=False)
session.install("nbformat", "nbstripout", "pytest", "nbconvert")
# Normalize all notebooks in the docs or notebooks directory
nb_files = list(Path("docs").rglob("*.ipynb"))
if nb_files:
session.run("nbstripout", *[str(f) for f in nb_files])
notebooks = session.posargs or ["docs/how_to/"]
session.run("pytest", "--nbmake", *notebooks, external=True)
@nox.session(name="pre-commit")
def lint(session):
"""Run pre-commit hooks (lint, format, etc.)."""
session.install("pre-commit", silent=False)
session.run("pre-commit", "run", "--all-files")
@nox.session(name="dev")
def dev_env(session):
"""Create a reusable developer venv with all dependencies."""
set_env(session, PROJECT_ENV)
session.install("virtualenv")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True)
@nox.session(name="all_tests", reuse_venv=True)
def run_all_tests(session):
"""Run unit tests and integration tests."""
run_unit(session)
run_integration(session)
@nox.session(name="doctests")
def run_doc_tests(session):
"""Run the doctests and generate the output(s) in the docs/build/ directory."""
set_env(session, PROJECT_ENV)
session.install("-e", ".[all,dev]", silent=False)
session.run("pytest", "--doctest-modules", "--doctest-plus", "modularml")
@nox.session(name="docs")
def build_docs(session):
"""Run doc tests."""
set_env(session, PROJECT_ENV)
session.install("-e", ".[all,dev,docs]", silent=False)
session.chdir("docs")
# Clean stale build artifacts to prevent cached duplicates
session.run("rm", "-rf", "_build", external=True)
sourcedir = "."
outputdir = "_build/html"
# Local development
if session.interactive:
session.run(
"sphinx-autobuild",
sourcedir,
outputdir,
"-b",
"html",
"-j",
"1",
"--open-browser",
"-qT",
)
# Runs in CI only, treating warnings as errors
# Run in single-threaded mode, see
# https://github.com/pydata/pydata-sphinx-theme/issues/1643
else:
session.run(
"sphinx-build",
"-W",
"--keep-going",
"-b",
"html",
sourcedir,
outputdir,
)