Skip to content

Commit 2bf2a15

Browse files
authored
Test with Nox (#264)
* Test with Nox Adds a `noxfile.py` that enables easier local testing across multiple Python versions. It's configued to use `uv` to speed up the generation of the test virtual environments. * Exclude noxfile from wheel * Test with Nox Adds a `noxfile.py` that enables easier local testing across multiple Python versions. It's configued to use `uv` to speed up the generation of the test virtual environments. * Exclude noxfile from wheel
1 parent a41fe8a commit 2bf2a15

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ exclude .coveragerc
2020
exclude .readthedocs.yml
2121
exclude **/*.ipynb
2222
exclude **/*.pyc
23+
exclude noxfile.py

noxfile.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import argparse
2+
3+
import nox
4+
import yaml
5+
6+
with open('./.github/workflows/main.yaml') as f:
7+
workflow = yaml.safe_load(f)
8+
9+
python_versions = workflow['jobs']['test']['strategy']['matrix']['python-version']
10+
# pydantic_versions = workflow['jobs']['test']['strategy']['matrix']['pydantic-version']
11+
12+
nox.options.default_venv_backend = 'uv'
13+
14+
15+
@nox.session(python=python_versions)
16+
@nox.parametrize('pydantic', ['<2', '>=2'])
17+
def tests(session: nox.Session, pydantic: str):
18+
"""Run py.test."""
19+
session.install('-r', 'dev-requirements.txt')
20+
session.install('.')
21+
session.install(f"pydantic{pydantic}")
22+
session.run('pytest', '--verbose', '--pdb')
23+
24+
25+
@nox.session
26+
def pre_commit(session: nox.Session):
27+
"""Run pre-commit."""
28+
session.install('pre-commit')
29+
session.run('pre-commit', 'run')
30+
31+
32+
@nox.session
33+
def docs(session: nox.Session):
34+
"""Build docs using Sphinx.
35+
36+
Add --live (nox -s docs -- --live) to run a live server
37+
Add --clean to clean docs directory first
38+
"""
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument('--clean', action='store_true', help='Clean the build directory first')
41+
parser.add_argument('--live', action='store_true', help='Run a live updating server for docs')
42+
args, posargs = parser.parse_known_args(session.posargs)
43+
44+
session.install('-r', 'dev-requirements.txt')
45+
session.install('.')
46+
47+
session.chdir('docs')
48+
session.install('-r', 'requirements.txt')
49+
session.install('sphinx-autobuild')
50+
51+
BUILDDIR = '_build'
52+
53+
if args.clean:
54+
session.run('rm', '-rf', f"{BUILDDIR}/*")
55+
56+
if args.live:
57+
session.run('sphinx-autobuild', '-b', 'dirhtml', 'source/', '_build/dirhtml/')
58+
else:
59+
session.run(
60+
'sphinx-build',
61+
'-b',
62+
'dirhtml',
63+
'-d',
64+
f"{BUILDDIR}/doctrees",
65+
'source/dirhtml',
66+
)
67+
68+
69+
nox.options.sessions = ['tests']

0 commit comments

Comments
 (0)