-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
162 lines (109 loc) · 4.03 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os
import shutil
import nox
@nox.session(name='cleanup', python=False)
def run_cleanup(_):
"""Use os/shutil to remove some files/directories"""
if os.path.exists('.coverage'):
os.remove('.coverage')
folders = ['.pytest_cache', '__pycache__']
for f in folders:
if os.path.exists(f):
shutil.rmtree(f)
@nox.session(name='linter', python=False)
def run_flake8(session):
"""
Run flake8 with the github config file
Use the optional 'format' argument to run autopep8 prior to the linter.
"""
if 'format' in session.posargs:
session.run('autopep8', '.', '--in-place', '--recursive',
'--global-config=.github/linters/.flake8')
session.run('flake8', '--config=.github/linters/.flake8')
@nox.session(name='codespell', python=False)
def run_codespell(session):
"""
Run codespell with the github config file
Use the optional 'write' argument to write the corrections directly into
the files. Otherwise, you will only see a summary of the found errors.
"""
command = ['codespell', '--config=.github/linters/.codespellrc']
if 'write' in session.posargs:
command.insert(1, '-w')
session.run(*command)
@nox.session(name='spellcheck', python=False)
def run_spellcheck(session):
"""
Run codespell with docs files included
Use the optional 'write' argument to write the corrections directly into
the files. Otherwise, you will only see a summary of the found errors.
"""
command = ['codespell', '--config=.github/linters/.codespellrc']
if 'write' in session.posargs:
command.insert(1, '-w')
run_codespell(session)
session.run(*command, 'docs/source')
@nox.session(name='tests', python=False)
def run_pytest(session):
"""
Run pytest and generate test/coverage reports
Use the optional 'parallel' argument to run the tests in parallel. As just
a flag, the number of workers will be determined automatically. Otherwise,
you can specify the number of workers using an int, e.g., parallel=4.
"""
command = [
'pytest',
'--cov=src/thevenin',
'--cov-report=html:reports/htmlcov',
'--cov-report=xml:reports/coverage.xml',
'--junitxml=reports/junit.xml',
'tests/',
]
for arg in session.posargs:
if arg.startswith('parallel='):
command[1:1] = ['-n', arg.split('=')[-1]]
elif arg.startswith('parallel'):
command[1:1] = ['-n', 'auto']
session.run(*command)
run_cleanup(session)
@nox.session(name='badges', python=False)
def run_genbadge(session):
"""Run genbadge to make test/coverage badges"""
session.run(
'genbadge', 'coverage', '-l',
'-i', 'reports/coverage.xml',
'-o', 'images/coverage.svg',
)
session.run(
'genbadge', 'tests', '-l',
'-i', 'reports/junit.xml',
'-o', 'images/tests.svg',
)
@nox.session(name='docs', python=False)
def run_sphinx(session):
"""
Run spellcheck and then use sphinx to build docs
Use the optional 'clean' argument to remove everything under the 'build'
and 'source/api' folders prior to re-building the docs. This is important
in cases where the api module names have been changed or when some navbars
are not showing new pages. In general, try without 'clean' first.
"""
if 'clean' in session.posargs:
os.chdir('docs')
session.run('make', 'clean')
if os.path.exists('source/api'):
shutil.rmtree('source/api')
os.chdir('..')
run_spellcheck(session)
session.run('sphinx-build', 'docs/source', 'docs/build')
@nox.session(name='pre-commit', python=False)
def run_pre_commit(session):
"""
Run all linters/tests and make new badges
Order of sessions: flake8, codespell, pytest, genbade. Using 'format' for
linter, 'write' for codespell, and/or 'parallel' for pytest is permitted.
"""
run_flake8(session)
run_codespell(session)
run_pytest(session)
run_genbadge(session)