-
Notifications
You must be signed in to change notification settings - Fork 5
/
noxfile.py
92 lines (72 loc) · 2.2 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
import os
import nox
nox.options.sessions = "lint_pylint", "typecheck", "test"
EDITABLE_TESTS = True
PYTHON_VERSIONS = None
if "GITHUB_ACTIONS" in os.environ:
PYTHON_VERSIONS = ["3.9", "3.11"]
EDITABLE_TESTS = False
@nox.session
def doc(session):
"""
Build the documentation.
Accepts the following arguments:
- open: open documentation after build
- clean: clean up the build folder
- <target> <options>: build the given <target> with the given <options>
"""
target = "html"
options = []
open_doc = "open" in session.posargs
clean = "clean" in session.posargs
if open_doc:
session.posargs.remove("open")
if clean:
session.posargs.remove("clean")
if session.posargs:
target = session.posargs[0]
options = session.posargs[1:]
session.install("-e", ".[doc]")
session.cd("doc")
if clean:
session.run("rm", "-rf", "_build")
session.run("sphinx-build", "-M", target, ".", "_build", *options)
if open_doc:
session.run("open", "_build/html/index.html")
@nox.session
def dev(session):
"""
Create a development environment in editable mode.
Activate it by running `source .nox/dev/bin/activate`.
"""
session.install("-e", ".[dev]")
@nox.session
def lint_pylint(session):
"""
Run pylint.
"""
session.install("-e", ".[lint_pylint]")
session.run("pylint", "fillname", "tests")
@nox.session
def typecheck(session):
"""
Typecheck the code using mypy.
"""
session.install("-e", ".[typecheck]")
session.run("mypy", "--strict", "-p", "fillname", "-p", "tests")
@nox.session(python=PYTHON_VERSIONS)
def test(session):
"""
Run the tests.
Accepts an additional arguments which are passed to the unittest module.
This can for example be used to selectively run test cases.
"""
args = [".[test]"]
if EDITABLE_TESTS:
args.insert(0, "-e")
session.install(*args)
if session.posargs:
session.run("coverage", "run", "-m", "unittest", session.posargs[0], "-v")
else:
session.run("coverage", "run", "-m", "unittest", "discover", "-v")
session.run("coverage", "report", "-m", "--fail-under=100")