-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
143 lines (105 loc) · 3.34 KB
/
noxfile.py
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
"""Automate everything everywhere all at once.
Requires [Nox](https://nox.thea.codes/).
- Run `nox -ls` to list all sessions.
- Run `nox -s <NAME>` to run the session _`<NAME>`_.
- Run `nox -s docs -p 3.12 -- --live` to build the docs with live-reloading.
"""
import tempfile
from nox import Session, options, session
options.stop_on_first_error = True
python_versions = ["3.12", "3.11", "3.10", "3.9", "3.8"]
def install_with_group(s: Session, group: str = "dev") -> None:
"""Install group dependencies from Poetry."""
with tempfile.NamedTemporaryFile() as requirements:
s.run(
"poetry",
"export",
"--without-hashes",
"--with",
group,
"--output",
requirements.name,
external=True,
)
s.install("-r", requirements.name)
s.install(".")
@session(python=python_versions)
def docs(s: Session) -> None:
"""Build the docs."""
args = ["-aWTE", "docs", "docs/_dist"]
sphinx_build = "sphinx-build"
if "--live" in s.posargs:
sphinx_build = "sphinx-autobuild"
s.posargs.remove("--live")
if s.posargs:
args = s.posargs + args
install_with_group(s, "docs")
s.run(sphinx_build, *args)
@session
def check_links(s: Session) -> None:
"""Check links in docs."""
args = ["-b", "linkcheck", "docs", "docs/_dist/_links"]
if s.posargs:
args = s.posargs + args
install_with_group(s, "docs")
s.run("sphinx-build", *args)
@session
def fmt(s: Session) -> None:
"""Format the code with ruff."""
install_with_group(s, "lint")
s.run("ruff", "check", ".", "--select", "I", "--fix")
s.run("ruff", "format", ".")
@session
def lint(s: Session) -> None:
"""Lint the code with ruff."""
install_with_group(s, "lint")
s.run("ruff", "check", ".")
@session(python=python_versions)
def tests(s: Session) -> None:
"""Run unit tests."""
args = s.posargs or ["--cov"]
install_with_group(s, "dev,docs")
s.run("pytest", *args)
@session(python=["3.8", "3.12"])
def typecheck(s: Session) -> None:
"""Typecheck."""
install_with_group(s, "dev")
s.run("mypy", ".", "--exclude", "docs")
@session(python=False)
def build(s: Session) -> None:
"""Build the packages using Poetry.
Since Poetry is installed globally,
skip the virtual environment creation.
"""
s.run("poetry", "build", external=True)
@session(python=False)
def export(s: Session) -> None:
"""Export Poetry dependencies for ReadTheDocs.
Since Poetry is installed globally,
skip the virtual environment creation.
"""
s.run(
"poetry",
"export",
"--with",
"docs",
"--without-hashes",
"--output",
"docs/requirements.txt",
external=True,
)
@session(python=False)
def publish(s: Session) -> None:
"""Publish this package to the Python package index (PyPI).
Since Poetry is installed globally,
skip the virtual environment creation.
Always build the package before publishing.
Requires the environment variable `POETRY_PYPI_TOKEN_PYPI`
with the token for publishing the package to PyPI.
"""
build(s)
s.run("poetry", "publish", external=True)
@session(python=False)
def clean(s: Session) -> None:
"""Delete artifacts."""
s.run("rm", "-rv", "dist", "docs/_dist")