[tox] envlist = check, clean, {py39,py310,py311,py312,py313}, report minversion = 4 [python-cli-options] byte-warnings = -b byte-errors = -bb max-isolation = -E -s -I # some-isolation = -I # FIXME: Python 2 shim. Is this equivalent to the above? some-isolation = -E -s warnings-to-errors = -Werror [testenv] description = Run pytest under {envpython} # deps = # pytest # pytest-asyncio # pytest-xdist # pytest-cov deps = -rrequirements{/}ci-wheel.txt commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -W 'ignore:Coverage failure::pytest_cov.plugin' \ -m pytest \ {tty:--color=yes} \ {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}} commands_post = -{envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'import atexit, os, sys; \ os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ import coverage; \ gh_summary_fd = open(\ os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a",\ ); \ atexit.register(gh_summary_fd.close); \ cov = coverage.Coverage(); \ cov.load(); \ cov.report(file=gh_summary_fd, output_format="markdown")' {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'import os, pathlib, sys; \ os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ cov_report_arg_prefix = "--cov-report=xml:"; \ test_report_arg_prefix = "--junitxml="; \ cov_reports = [\ arg[len(cov_report_arg_prefix):] for arg in sys.argv \ if arg.startswith(cov_report_arg_prefix)\ ]; \ test_reports = [\ arg[len(test_report_arg_prefix):] for arg in sys.argv \ if arg.startswith(test_report_arg_prefix)\ ]; \ cov_report_file = cov_reports[-1] if cov_reports else None; \ test_report_file = test_reports[-1] if test_reports else None; \ gh_output_fd = open(\ os.environ["GITHUB_OUTPUT"], encoding="utf-8", mode="a",\ ); \ cov_report_file and \ print(f"cov-report-files={cov_report_file !s}", file=gh_output_fd); \ test_report_file and \ print(f"test-result-files={test_report_file !s}", file=gh_output_fd); \ print("codecov-flags=pytest", file=gh_output_fd); \ gh_output_fd.close()' \ {posargs} # Print out the output coverage dir and a way to serve html: {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c\ 'import pathlib, shlex, sys; \ cov_html_report_arg_prefix = "--cov-report=html:"; \ cov_html_reports = [\ arg[len(cov_html_report_arg_prefix):] for arg in sys.argv \ if arg.startswith(cov_html_report_arg_prefix)\ ]; \ cov_html_reports or sys.exit(); \ cov_html_report_dir = pathlib.Path(cov_html_reports[-1]); \ index_file = cov_html_report_dir / "index.html";\ index_file.exists() or sys.exit(); \ html_url = f"file://\{index_file\}";\ browse_cmd = shlex.join(("python3", "-Im", "webbrowser", html_url)); \ serve_cmd = shlex.join((\ "python3", "-Im", "http.server", \ "--directory", str(cov_html_report_dir), "0", \ )); \ print(f"\nTo open the HTML coverage report, run\n\n\ \t\{browse_cmd !s\}\n");\ print(f"To serve \ the HTML coverage report with a local web server, use\n\n\ \t\{serve_cmd !s\}\n")' \ {posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}} package = editable pass_env = CI GITHUB_* SSH_AUTH_SOCK TERM set_env = COVERAGE_PROCESS_START = {toxinidir}{/}.coveragerc wheel_build_env = .pkg [testenv:cleanup-dists] description = Wipe the the dist{/} folder deps = commands_pre = commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'import os, shutil, sys; \ dists_dir = "{toxinidir}{/}dist{/}"; \ shutil.rmtree(dists_dir, ignore_errors=True); \ sys.exit(os.path.exists(dists_dir))' commands_post = package = skip [testenv:build-dists] description = Build dists with {basepython} and put them into the dist{/} folder depends = cleanup-dists deps = build commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -m build \ {posargs:} commands_post = package = skip [testenv:metadata-validation] description = Verify that dists under the `dist{/}` dir have valid metadata depends = build-dists deps = -rrequirements{/}wheel.txt commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -m twine \ check \ --strict \ dist{/}* commands_post = package = skip [testenv:pre-commit] description = Run the quality checks under {basepython}; run as `SKIP=check-id1,check-id2 tox r -e pre-commit` to instruct the underlying `pre-commit` invocation avoid running said checks; Use `tox r -e pre-commit -- check-id1 --all-files` to select checks matching IDs aliases{:} `tox r -e pre-commit -- mypy --all-files` will run 3 MyPy invocations, but `tox r -e pre-commit -- mypy-py313 --all-files` runs one. commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -m pre_commit \ run \ --color=always \ --show-diff-on-failure \ {posargs:--all-files} # Print out the advice on how to install pre-commit from this env into Git: -{envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'cmd = "{envpython} -m pre_commit install"; \ scr_width = len(cmd) + 10; \ sep = "=" * scr_width; \ cmd_str = " $ \{cmd\}";' \ 'print(f"\n\{sep\}\nTo install pre-commit hooks into the Git repo, run:\ \n\n\{cmd_str\}\n\n\{sep\}\n")' commands_post = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'import os, pathlib, sys; \ os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ project_root_path = pathlib.Path(r"{toxinidir}"); \ test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \ coverage_result_files = ",".join(\ str(xml_path.relative_to(project_root_path)) \ for xml_path in test_results_dir.glob("mypy--py-*{/}cobertura.xml")\ ); \ gh_output_fd = open(\ os.environ["GITHUB_OUTPUT"], encoding="utf-8", mode="a",\ ); \ print(\ f"cov-report-files={coverage_result_files !s}", file=gh_output_fd\ ); \ print("codecov-flags=MyPy", file=gh_output_fd); \ gh_output_fd.close()' {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c \ 'import itertools, os, pathlib, shlex, sys; \ os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \ test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \ text_and_json_reports = itertools.chain( \ test_results_dir.glob("mypy--py-*{/}*.json"), \ test_results_dir.glob("mypy--py-*{/}*.txt"), \ ); \ report_contents = { \ report{:} report.read_text() \ for report in text_and_json_reports \ }; \ reports_summary_text_blob = "\n\n".join( \ f"\N\{NUMBER SIGN\}\N\{NUMBER SIGN\} {report_path.parent.name}{:} " \ f"`{report_path.name}`\n\n" \ f"```{report_path.suffix[1:]}\n{report_text}\n```\n" \ for report_path, report_text in report_contents.items() \ ); \ gh_summary_fd = open( \ os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a", \ ); \ print(reports_summary_text_blob, file=gh_summary_fd); \ gh_summary_fd.close()' # Print out the output coverage dir and a way to serve html: {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c\ 'import os, pathlib, sys; \ os.getenv("GITHUB_ACTIONS") == "true" and sys.exit(); \ len(sys.argv) >= 3 and all(\ arg != "mypy" and not arg.startswith("mypy-py3") \ for arg in sys.argv \ ) and sys.exit(); \ project_root_path = pathlib.Path(r"{toxinidir}"); \ test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \ coverage_html_report_urls = [\ f"file://\{xml_path !s\}" \ for xml_path in test_results_dir.glob("mypy--py-*{/}index.html")\ ]; \ coverage_html_report_open_cmds = [\ f"python3 -Im webbrowser \N\{QUOTATION MARK\}\{html_url !s\}\N\{QUOTATION MARK\}" \ for html_url in coverage_html_report_urls\ ]; \ coverage_html_report_open_cmds_blob = "\n\n\t".join(\ coverage_html_report_open_cmds,\ ); \ print(\ f"\nTo open the HTML coverage reports, run\n\n\ \t\{coverage_html_report_open_cmds_blob !s\}\n"\ ); \ print(\ f"[*] Find rest of JSON and text reports, are in the same directories."\ )\ ' \ {posargs:--all-files} deps = -rrequirements{/}wheel.txt isolated_build = true package = skip pass_env = {[testenv]pass_env} SKIP # set this variable [testenv:build-docs] # NOTE: Passing the `is_unversioned` tag speeds up rebuilds in dev env allowlist_externals = git description = Build The Docs changedir = docs{/} commands_pre = # Retrieve possibly missing commits: -git fetch --unshallow -git fetch --tags # Clean up sphinxcontrib-apidoc generated RST files: -git clean -x -f -- 'pkg{/}*.rst' commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -m sphinx \ -j auto \ -b html \ {tty:--color} \ -a \ -n \ -W --keep-going \ -d '{temp_dir}{/}.doctrees' \ . \ {posargs:{envtmpdir}{/}html -t is_unversioned} commands_post = # Print out the output docs dir and a way to serve html: {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -c\ 'import os, pathlib;\ IS_RTD_ENV = os.getenv("READTHEDOCS", "False") == "True";\ docs_dir = pathlib.Path(r"{envdir}") / r"{envtmpdir}" / "html";\ index_file = docs_dir / "index.html";\ docs_url = os.environ["READTHEDOCS_CANONICAL_URL"] if IS_RTD_ENV \ else f"file://\{index_file\}";\ print(f"\nTo open the documentation, run\n\n\ \tpython3 -Im webbrowser \ \N\{QUOTATION MARK\}\{docs_url !s\}\N\{QUOTATION MARK\}\n");\ not IS_RTD_ENV and \ print(f"To serve \ the docs with a local web server, use\n\n\ \tpython3 -Im http.server --directory \ \N\{QUOTATION MARK\}\{docs_dir\}\N\{QUOTATION MARK\} 0\n")' deps = -r{toxinidir}{/}requirements{/}doc.txt pass_env = {[testenv]pass_env} READTHEDOCS* # Present @ RTD [testenv:spellcheck-docs] allowlist_externals = {[testenv:build-docs]allowlist_externals} description = Spellcheck The Docs changedir = {[testenv:build-docs]changedir} commands_pre = # Retrieve possibly missing commits: -git fetch --unshallow -git fetch --tags # Clean up sphinxcontrib-apidoc generated RST files: -git clean -x -f -- 'pkg{/}*.rst' commands = {envpython} \ {[python-cli-options]byte-errors} \ {[python-cli-options]max-isolation} \ {[python-cli-options]warnings-to-errors} \ -m sphinx \ -j auto \ {tty:--color} \ -a \ -n \ -W --keep-going \ -b spelling --color \ -d "{temp_dir}{/}.doctrees" \ . "{toxworkdir}{/}spelling" commands_post = deps = -r{toxinidir}{/}requirements{/}doc-spelling.txt pass_env = {[testenv:build-docs]pass_env} [testenv:check] basepython = python3.13 deps = wheel flake8 docutils pygments twine build commands = flake8 aiosignal tests python -m build python -m twine check --strict dist/* commands_post = [testenv:clean] basepython = python3.13 deps = coverage skip_install = true commands = coverage erase commands_post = [testenv:report] basepython = python3.13 deps = coverage skip_install = true commands = coverage report coverage html {envpython} -c '\ print("python -m webbrowser \ \N{Apostrophe}file://{toxinidir}/htmlcov/index.html\N{Apostrophe}")\ ' commands_post =