-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
noxfile.py
189 lines (141 loc) · 6.22 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import glob
import os
import shutil
import sys
import nox
import nox_poetry
sys.path.append('.')
from noxutil import get_versions
CURRENT_PYTHON = (('pypy' if hasattr(sys, 'pypy_version_info') else '')
+ f'{sys.version_info.major}.{sys.version_info.minor}')
nox.options.sessions = ['check', 'check_docs',
f'unit-{CURRENT_PYTHON}(wheel)',
f'regression-{CURRENT_PYTHON}(wheel)']
PYTHONS = ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
PYTHONS += ['pypy3'] if os.getenv('CI') else ['pypy3.10']
DEPENDENCIES = ['pytest', 'pytest-xdist', 'pytest-cov', 'coverage', 'Sphinx']
if os.getenv('GITHUB_SHA'):
DEPENDENCIES.append('pytest-github-actions-annotate-failures')
def parametrize_dist():
return nox.parametrize('dist', ['sdist', 'wheel'], ids=['sdist', 'wheel'])
def parametrize(dependency, granularity='minor', python=CURRENT_PYTHON):
versions = get_versions(dependency, granularity, python)
if python != CURRENT_PYTHON:
for version in get_versions(dependency, granularity, CURRENT_PYTHON):
versions.remove(version)
return nox.parametrize(dependency, versions)
# sessions
@nox_poetry.session
def check(session):
session.run('poetry', 'check', external=True)
@nox_poetry.session
def check_docs(session):
_install(session, dependencies=['doc8', 'sphinx-immaterial',
'sphinxcontrib-autoprogram'])
session.run('doc8', 'README.rst', 'CHANGES.rst', 'CONTRIBUTING.rst',
'DEVELOPING.rst', 'doc')
session.run('python', 'doc/build.py', 'doctest')
@nox_poetry.session
def build_docs(session):
_install(session, dependencies=['Sphinx', 'sphinx-immaterial',
'sphinxcontrib-autoprogram'])
session.chdir('doc')
session.run('python', 'build.py', *session.posargs)
# copy 'showcase' directory to the HTML output directory
shutil.copytree('showcase', '_build/html/showcase', dirs_exist_ok=True)
# copy PDF docs to the HTML output directory
for pdf in glob.glob('_build/rinoh/*.pdf'):
shutil.copy(pdf, '_build/html')
@nox_poetry.session(python=PYTHONS)
@parametrize_dist()
def unit(session, dist):
_unit(session, dist=dist)
@nox_poetry.session
@parametrize('sphinx')
def unit_sphinx(session, sphinx):
_unit(session, sphinx=sphinx, ignore_deprecation_warnings=True)
@nox_poetry.session(python='3.9')
@parametrize('sphinx', python='3.9')
def unit_sphinx_py39(session, sphinx):
_unit(session, sphinx=sphinx, ignore_deprecation_warnings=True)
@nox_poetry.session(python=PYTHONS)
@parametrize_dist()
def regression(session, dist):
_regression(session, dist=dist)
@nox_poetry.session
@parametrize('docutils')
def regression_docutils(session, docutils):
_regression(session, docutils=docutils, ignore_deprecation_warnings=True)
@nox_poetry.session
@parametrize('sphinx')
def regression_sphinx(session, sphinx):
_regression(session, sphinx=sphinx, ignore_deprecation_warnings=True)
@nox_poetry.session(python='3.9')
@parametrize('sphinx', python='3.9')
def regression_sphinx_py39(session, sphinx):
_regression(session, sphinx=sphinx, ignore_deprecation_warnings=True)
# utility functions
def _install(session, docutils=None, sphinx=None, dist='wheel',
dependencies=[]):
session.poetry.installroot(distribution_format=dist)
deps = []
if docutils:
deps.append(f"docutils=={docutils}")
major, minor, *_ = docutils.split('.')
if (int(major), int(minor)) < (0, 18):
assert sphinx is None
sphinx = '5.3.0'
if sphinx:
deps.append(f"sphinx=={sphinx}")
major, _ = sphinx.split('.', maxsplit=1)
if int(major) < 4:
# https://github.com/sphinx-doc/sphinx/issues/10291
deps.append("jinja2<3.1")
elif int(major) < 6:
deps.append("myst-parser==0.18.1")
if int(major) < 5:
# https://github.com/sphinx-doc/sphinx/issues/11890
deps.append("alabaster==0.7.13")
deps.append("sphinxcontrib-applehelp==1.0.4")
deps.append("sphinxcontrib-devhelp==1.0.2")
deps.append("sphinxcontrib-htmlhelp==2.0.1")
deps.append("sphinxcontrib-serializinghtml==1.1.5")
deps.append("sphinxcontrib-qthelp==1.0.3")
if dependencies:
session.install(*(d for d in dependencies
if not (sphinx and d.lower() == 'sphinx')))
if deps:
session.run("pip", "install", *deps)
def _unit(session, docutils=None, sphinx=None, dist='wheel',
ignore_deprecation_warnings=False):
_install(session, docutils=docutils, sphinx=sphinx, dist=dist,
dependencies=DEPENDENCIES)
mark_expr = ['-m', 'with_sphinx'] if sphinx else []
if dist == 'sdist':
session.env['WITH_COVERAGE'] = '0'
_run_tests(session, 'tests', *mark_expr,
ignore_deprecation_warnings=ignore_deprecation_warnings)
def _regression(session, docutils=None, sphinx=None, dist='wheel',
ignore_deprecation_warnings=False):
_install(session, docutils=docutils, sphinx=sphinx, dist=dist,
dependencies=[*DEPENDENCIES, 'defusedxml', # for Sphinx>=7.3
'pytest-assume', 'pytest-console-scripts'])
mark_expr = ['-m', 'with_sphinx'] if sphinx else ['-m', 'not longrunning']
if dist == 'sdist':
session.env['WITH_COVERAGE'] = '0'
_run_tests(session, 'tests_regression', *mark_expr,
'--script-launch-mode=subprocess',
ignore_deprecation_warnings=ignore_deprecation_warnings)
def _run_tests(session, tests_dir, *args, ignore_deprecation_warnings=False):
filterwarnings = ['-W', ''] if ignore_deprecation_warnings else []
session.run('python', 'run_tests.py', *args, *filterwarnings,
*session.posargs, tests_dir)
# currently unmaintained sessions
@nox_poetry.session(python='python3.7')
def macapp(session):
session.run('python', 'macapp.py', '--use-tox-sdist')
@nox_poetry.session(python='python3.6')
def wininst(session):
session.env['SPHINXOPTS'] = '"-Dhtml_theme=bizstyle"'
session.run('python', 'doc/build.py', 'rinoh', 'htmlhelp')
session.run('python', 'wininst.py', '--use-tox-sdist')