Debian Codegraph @

tox.ini

raw
1 [tox]
2 envlist = check, clean, {py39,py310,py311,py312,py313}, report
3 minversion = 4
4
5
6 [python-cli-options]
7 byte-warnings = -b
8 byte-errors = -bb
9 max-isolation = -E -s -I
10 # some-isolation = -I
11 # FIXME: Python 2 shim. Is this equivalent to the above?
12 some-isolation = -E -s
13 warnings-to-errors = -Werror
14
15
16 [testenv]
17 description = Run pytest under {envpython}
18 # deps =
19 # pytest
20 # pytest-asyncio
21 # pytest-xdist
22 # pytest-cov
23 deps = -rrequirements{/}ci-wheel.txt
24
25 commands =
26 {envpython} \
27 {[python-cli-options]byte-errors} \
28 {[python-cli-options]max-isolation} \
29 {[python-cli-options]warnings-to-errors} \
30 -W 'ignore:Coverage failure::pytest_cov.plugin' \
31 -m pytest \
32 {tty:--color=yes} \
33 {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}}
34 commands_post =
35 -{envpython} \
36 {[python-cli-options]byte-errors} \
37 {[python-cli-options]max-isolation} \
38 {[python-cli-options]warnings-to-errors} \
39 -c \
40 'import atexit, os, sys; \
41 os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \
42 import coverage; \
43 gh_summary_fd = open(\
44 os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a",\
45 ); \
46 atexit.register(gh_summary_fd.close); \
47 cov = coverage.Coverage(); \
48 cov.load(); \
49 cov.report(file=gh_summary_fd, output_format="markdown")'
50 {envpython} \
51 {[python-cli-options]byte-errors} \
52 {[python-cli-options]max-isolation} \
53 {[python-cli-options]warnings-to-errors} \
54 -c \
55 'import os, pathlib, sys; \
56 os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \
57 cov_report_arg_prefix = "--cov-report=xml:"; \
58 test_report_arg_prefix = "--junitxml="; \
59 cov_reports = [\
60 arg[len(cov_report_arg_prefix):] for arg in sys.argv \
61 if arg.startswith(cov_report_arg_prefix)\
62 ]; \
63 test_reports = [\
64 arg[len(test_report_arg_prefix):] for arg in sys.argv \
65 if arg.startswith(test_report_arg_prefix)\
66 ]; \
67 cov_report_file = cov_reports[-1] if cov_reports else None; \
68 test_report_file = test_reports[-1] if test_reports else None; \
69 gh_output_fd = open(\
70 os.environ["GITHUB_OUTPUT"], encoding="utf-8", mode="a",\
71 ); \
72 cov_report_file and \
73 print(f"cov-report-files={cov_report_file !s}", file=gh_output_fd); \
74 test_report_file and \
75 print(f"test-result-files={test_report_file !s}", file=gh_output_fd); \
76 print("codecov-flags=pytest", file=gh_output_fd); \
77 gh_output_fd.close()' \
78 {posargs}
79 # Print out the output coverage dir and a way to serve html:
80 {envpython} \
81 {[python-cli-options]byte-errors} \
82 {[python-cli-options]max-isolation} \
83 {[python-cli-options]warnings-to-errors} \
84 -c\
85 'import pathlib, shlex, sys; \
86 cov_html_report_arg_prefix = "--cov-report=html:"; \
87 cov_html_reports = [\
88 arg[len(cov_html_report_arg_prefix):] for arg in sys.argv \
89 if arg.startswith(cov_html_report_arg_prefix)\
90 ]; \
91 cov_html_reports or sys.exit(); \
92 cov_html_report_dir = pathlib.Path(cov_html_reports[-1]); \
93 index_file = cov_html_report_dir / "index.html";\
94 index_file.exists() or sys.exit(); \
95 html_url = f"file://\{index_file\}";\
96 browse_cmd = shlex.join(("python3", "-Im", "webbrowser", html_url)); \
97 serve_cmd = shlex.join((\
98 "python3", "-Im", "http.server", \
99 "--directory", str(cov_html_report_dir), "0", \
100 )); \
101 print(f"\nTo open the HTML coverage report, run\n\n\
102 \t\{browse_cmd !s\}\n");\
103 print(f"To serve \
104 the HTML coverage report with a local web server, use\n\n\
105 \t\{serve_cmd !s\}\n")' \
106 {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}}
107 package = editable
108 pass_env =
109 CI
110 GITHUB_*
111 SSH_AUTH_SOCK
112 TERM
113 set_env =
114 COVERAGE_PROCESS_START = {toxinidir}{/}.coveragerc
115 wheel_build_env = .pkg
116
117
118 [testenv:cleanup-dists]
119 description =
120 Wipe the the dist{/} folder
121 deps =
122 commands_pre =
123 commands =
124 {envpython} \
125 {[python-cli-options]byte-errors} \
126 {[python-cli-options]max-isolation} \
127 {[python-cli-options]warnings-to-errors} \
128 -c \
129 'import os, shutil, sys; \
130 dists_dir = "{toxinidir}{/}dist{/}"; \
131 shutil.rmtree(dists_dir, ignore_errors=True); \
132 sys.exit(os.path.exists(dists_dir))'
133 commands_post =
134 package = skip
135
136
137 [testenv:build-dists]
138 description =
139 Build dists with {basepython} and put them into the dist{/} folder
140 depends =
141 cleanup-dists
142 deps =
143 build
144 commands =
145 {envpython} \
146 {[python-cli-options]byte-errors} \
147 {[python-cli-options]max-isolation} \
148 {[python-cli-options]warnings-to-errors} \
149 -m build \
150 {posargs:}
151 commands_post =
152 package = skip
153
154
155 [testenv:metadata-validation]
156 description =
157 Verify that dists under the `dist{/}` dir
158 have valid metadata
159 depends =
160 build-dists
161 deps = -rrequirements{/}wheel.txt
162 commands =
163 {envpython} \
164 {[python-cli-options]byte-errors} \
165 {[python-cli-options]max-isolation} \
166 {[python-cli-options]warnings-to-errors} \
167 -m twine \
168 check \
169 --strict \
170 dist{/}*
171 commands_post =
172 package = skip
173
174
175 [testenv:pre-commit]
176 description =
177 Run the quality checks under {basepython}; run as
178 `SKIP=check-id1,check-id2 tox r -e pre-commit` to instruct the underlying
179 `pre-commit` invocation avoid running said checks; Use
180 `tox r -e pre-commit -- check-id1 --all-files` to select checks matching IDs
181 aliases{:} `tox r -e pre-commit -- mypy --all-files` will run 3 MyPy
182 invocations, but `tox r -e pre-commit -- mypy-py313 --all-files` runs one.
183 commands =
184 {envpython} \
185 {[python-cli-options]byte-errors} \
186 {[python-cli-options]max-isolation} \
187 {[python-cli-options]warnings-to-errors} \
188 -m pre_commit \
189 run \
190 --color=always \
191 --show-diff-on-failure \
192 {posargs:--all-files}
193
194 # Print out the advice on how to install pre-commit from this env into Git:
195 -{envpython} \
196 {[python-cli-options]byte-errors} \
197 {[python-cli-options]max-isolation} \
198 {[python-cli-options]warnings-to-errors} \
199 -c \
200 'cmd = "{envpython} -m pre_commit install"; \
201 scr_width = len(cmd) + 10; \
202 sep = "=" * scr_width; \
203 cmd_str = " $ \{cmd\}";' \
204 'print(f"\n\{sep\}\nTo install pre-commit hooks into the Git repo, run:\
205 \n\n\{cmd_str\}\n\n\{sep\}\n")'
206 commands_post =
207 {envpython} \
208 {[python-cli-options]byte-errors} \
209 {[python-cli-options]max-isolation} \
210 {[python-cli-options]warnings-to-errors} \
211 -c \
212 'import os, pathlib, sys; \
213 os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \
214 project_root_path = pathlib.Path(r"{toxinidir}"); \
215 test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \
216 coverage_result_files = ",".join(\
217 str(xml_path.relative_to(project_root_path)) \
218 for xml_path in test_results_dir.glob("mypy--py-*{/}cobertura.xml")\
219 ); \
220 gh_output_fd = open(\
221 os.environ["GITHUB_OUTPUT"], encoding="utf-8", mode="a",\
222 ); \
223 print(\
224 f"cov-report-files={coverage_result_files !s}", file=gh_output_fd\
225 ); \
226 print("codecov-flags=MyPy", file=gh_output_fd); \
227 gh_output_fd.close()'
228 {envpython} \
229 {[python-cli-options]byte-errors} \
230 {[python-cli-options]max-isolation} \
231 {[python-cli-options]warnings-to-errors} \
232 -c \
233 'import itertools, os, pathlib, shlex, sys; \
234 os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \
235 test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \
236 text_and_json_reports = itertools.chain( \
237 test_results_dir.glob("mypy--py-*{/}*.json"), \
238 test_results_dir.glob("mypy--py-*{/}*.txt"), \
239 ); \
240 report_contents = { \
241 report{:} report.read_text() \
242 for report in text_and_json_reports \
243 }; \
244 reports_summary_text_blob = "\n\n".join( \
245 f"\N\{NUMBER SIGN\}\N\{NUMBER SIGN\} {report_path.parent.name}{:} " \
246 f"`{report_path.name}`\n\n" \
247 f"```{report_path.suffix[1:]}\n{report_text}\n```\n" \
248 for report_path, report_text in report_contents.items() \
249 ); \
250 gh_summary_fd = open( \
251 os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a", \
252 ); \
253 print(reports_summary_text_blob, file=gh_summary_fd); \
254 gh_summary_fd.close()'
255 # Print out the output coverage dir and a way to serve html:
256 {envpython} \
257 {[python-cli-options]byte-errors} \
258 {[python-cli-options]max-isolation} \
259 {[python-cli-options]warnings-to-errors} \
260 -c\
261 'import os, pathlib, sys; \
262 os.getenv("GITHUB_ACTIONS") == "true" and sys.exit(); \
263 len(sys.argv) >= 3 and all(\
264 arg != "mypy" and not arg.startswith("mypy-py3") \
265 for arg in sys.argv \
266 ) and sys.exit(); \
267 project_root_path = pathlib.Path(r"{toxinidir}"); \
268 test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \
269 coverage_html_report_urls = [\
270 f"file://\{xml_path !s\}" \
271 for xml_path in test_results_dir.glob("mypy--py-*{/}index.html")\
272 ]; \
273 coverage_html_report_open_cmds = [\
274 f"python3 -Im webbrowser \N\{QUOTATION MARK\}\{html_url !s\}\N\{QUOTATION MARK\}" \
275 for html_url in coverage_html_report_urls\
276 ]; \
277 coverage_html_report_open_cmds_blob = "\n\n\t".join(\
278 coverage_html_report_open_cmds,\
279 ); \
280 print(\
281 f"\nTo open the HTML coverage reports, run\n\n\
282 \t\{coverage_html_report_open_cmds_blob !s\}\n"\
283 ); \
284 print(\
285 f"[*] Find rest of JSON and text reports, are in the same directories."\
286 )\
287 ' \
288 {posargs:--all-files}
289 deps = -rrequirements{/}wheel.txt
290 isolated_build = true
291 package = skip
292 pass_env =
293 {[testenv]pass_env}
294 SKIP # set this variable
295
296
297 [testenv:build-docs]
298 # NOTE: Passing the `is_unversioned` tag speeds up rebuilds in dev env
299 allowlist_externals =
300 git
301 description = Build The Docs
302 changedir = docs{/}
303 commands_pre =
304 # Retrieve possibly missing commits:
305 -git fetch --unshallow
306 -git fetch --tags
307
308 # Clean up sphinxcontrib-apidoc generated RST files:
309 -git clean -x -f -- 'pkg{/}*.rst'
310 commands =
311 {envpython} \
312 {[python-cli-options]byte-errors} \
313 {[python-cli-options]max-isolation} \
314 {[python-cli-options]warnings-to-errors} \
315 -m sphinx \
316 -j auto \
317 -b html \
318 {tty:--color} \
319 -a \
320 -n \
321 -W --keep-going \
322 -d '{temp_dir}{/}.doctrees' \
323 . \
324 {posargs:{envtmpdir}{/}html -t is_unversioned}
325 commands_post =
326 # Print out the output docs dir and a way to serve html:
327 {envpython} \
328 {[python-cli-options]byte-errors} \
329 {[python-cli-options]max-isolation} \
330 {[python-cli-options]warnings-to-errors} \
331 -c\
332 'import os, pathlib;\
333 IS_RTD_ENV = os.getenv("READTHEDOCS", "False") == "True";\
334 docs_dir = pathlib.Path(r"{envdir}") / r"{envtmpdir}" / "html";\
335 index_file = docs_dir / "index.html";\
336 docs_url = os.environ["READTHEDOCS_CANONICAL_URL"] if IS_RTD_ENV \
337 else f"file://\{index_file\}";\
338 print(f"\nTo open the documentation, run\n\n\
339 \tpython3 -Im webbrowser \
340 \N\{QUOTATION MARK\}\{docs_url !s\}\N\{QUOTATION MARK\}\n");\
341 not IS_RTD_ENV and \
342 print(f"To serve \
343 the docs with a local web server, use\n\n\
344 \tpython3 -Im http.server --directory \
345 \N\{QUOTATION MARK\}\{docs_dir\}\N\{QUOTATION MARK\} 0\n")'
346 deps =
347 -r{toxinidir}{/}requirements{/}doc.txt
348 pass_env =
349 {[testenv]pass_env}
350 READTHEDOCS* # Present @ RTD
351
352
353 [testenv:spellcheck-docs]
354 allowlist_externals =
355 {[testenv:build-docs]allowlist_externals}
356 description = Spellcheck The Docs
357 changedir = {[testenv:build-docs]changedir}
358 commands_pre =
359 # Retrieve possibly missing commits:
360 -git fetch --unshallow
361 -git fetch --tags
362
363 # Clean up sphinxcontrib-apidoc generated RST files:
364 -git clean -x -f -- 'pkg{/}*.rst'
365 commands =
366 {envpython} \
367 {[python-cli-options]byte-errors} \
368 {[python-cli-options]max-isolation} \
369 {[python-cli-options]warnings-to-errors} \
370 -m sphinx \
371 -j auto \
372 {tty:--color} \
373 -a \
374 -n \
375 -W --keep-going \
376 -b spelling --color \
377 -d "{temp_dir}{/}.doctrees" \
378 . "{toxworkdir}{/}spelling"
379 commands_post =
380 deps =
381 -r{toxinidir}{/}requirements{/}doc-spelling.txt
382 pass_env =
383 {[testenv:build-docs]pass_env}
384
385
386 [testenv:check]
387 basepython = python3.13
388
389 deps =
390 wheel
391 flake8
392 docutils
393 pygments
394 twine
395 build
396
397 commands =
398 flake8 aiosignal tests
399 python -m build
400 python -m twine check --strict dist/*
401 commands_post =
402
403 [testenv:clean]
404 basepython = python3.13
405
406 deps = coverage
407 skip_install = true
408
409 commands =
410 coverage erase
411 commands_post =
412
413 [testenv:report]
414 basepython = python3.13
415
416 deps = coverage
417 skip_install = true
418
419 commands =
420 coverage report
421 coverage html
422 {envpython} -c '\
423 print("python -m webbrowser \
424 \N{Apostrophe}file://{toxinidir}/htmlcov/index.html\N{Apostrophe}")\
425 '
426 commands_post =