-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
128 lines (102 loc) · 3.06 KB
/
noxfile.py
File metadata and controls
128 lines (102 loc) · 3.06 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
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 format(session):
"""
Autoformat source files.
If argument check is given, only reports changes.
"""
session.install("-e", ".[format]")
check = "check" in session.posargs
autoflake_args = [
"--in-place",
"--imports=<project>",
"--ignore-init-module-imports",
"--remove-unused-variables",
"-r",
"src",
"tests",
]
if check:
autoflake_args.remove("--in-place")
session.run("autoflake", *autoflake_args)
isort_args = ["--profile", "black", "src", "tests"]
if check:
isort_args.insert(0, "--check")
isort_args.insert(1, "--diff")
session.run("isort", *isort_args)
black_args = ["src", "tests"]
if check:
black_args.insert(0, "--check")
black_args.insert(1, "--diff")
session.run("black", *black_args)
@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", "<project>", "tests")
@nox.session
def typecheck(session):
"""
Typecheck the code using mypy.
"""
session.install("-e", ".[typecheck]")
session.run("mypy", "--strict", "-p", "<project>", "-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")