From 4e2dc6124dc3e75d065673bc9b005d9c12f3fe4c Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:56:32 +0300 Subject: [PATCH 1/2] maintain: Convert tox conf to native TOML --- pyproject.toml | 149 +++++++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 68 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0874f68..573cefe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,77 +60,90 @@ xfail_strict = true [tool.tox] -legacy_tox_ini = ''' -[tox] +requires = ["tox>=4.21.1"] # Only run pytest envs when no args given to tox -envlist = py{39,310,311,312,313} -isolated_build = True - -[testenv:py{39,310,311,312,313}] -description = run tests -deps = - -r tests/requirements.txt -commands = - pytest {posargs:--cov} - -[testenv:profile] -description = run profiler (use e.g. `firefox .tox/prof/combined.svg` to open) -deps = - -r tests/requirements.txt - pytest-profiling -commands = - pytest tests/test_for_profiler.py --profile-svg --pstats-dir "{toxworkdir}/prof" - python -c 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "combined.svg"))' - -[testenv:pre-commit] -description = run linters (except mypy) -skip_install = True -deps = pre-commit -commands = pre-commit run {posargs:--all} - -[testenv:mypy] -description = run mypy -basepython = python3.11 -deps = - -r tests/requirements.txt - mypy==1.11.2 -commands = - mypy {posargs:src/ tests/} - -[testenv:hook] -description = test mdformat's own pre-commit hook against the README file -skip_install = True -deps = pre-commit -commands = - pre-commit try-repo . mdformat --files README.md - -[testenv:cli] -description = run mdformat's own CLI -commands = mdformat {posargs} - -[testenv:docs] -description = invoke sphinx-build to build the HTML docs -skip_install = True -deps = - -r docs/requirements.txt -commands = - sphinx-build -d "{toxworkdir}/docs_doctree" docs/ "{toxworkdir}/docs_out" -W -b html {posargs} - python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))' - -[testenv:fuzz] -description = run the fuzzer (needs "apt install clang") -deps = - -r fuzzer/requirements.txt -allowlist_externals = - mkdir - cp -commands = +env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"] + +[tool.tox.env_run_base] +description = "run tests under {base_python}" +deps = [ + "-r tests/requirements.txt", +] +commands = [ + ["pytest", { replace = "posargs", default = ["--cov"], extend = true }], +] + +[tool.tox.env."profile"] +description = "run profiler (use e.g. `firefox .tox/prof/combined.svg` to open)" +deps = [ + "-r tests/requirements.txt", + "pytest-profiling", +] +commands = [ + ["pytest", "tests/test_for_profiler.py", "--profile-svg", "--pstats-dir", "{toxworkdir}/prof"], + ["python", "-c", 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "combined.svg"))'], +] + +[tool.tox.env."pre-commit"] +description = "run linters (except mypy)" +skip_install = true +deps = ["pre-commit"] +commands = [ + ["pre-commit", "run", { replace = "posargs", default = ["--all"], extend = true }], +] + +[tool.tox.env."mypy"] +description = "run mypy" +basepython = "python3.11" +deps = [ + "-r tests/requirements.txt", + "mypy==1.11.2", +] +commands = [ + ["mypy", { replace = "posargs", default = ["src/", "tests/"], extend = true }], +] + +[tool.tox.env."hook"] +description = "test mdformat's own pre-commit hook against the README file" +skip_install = true +deps = ["pre-commit"] +commands = [ + ["pre-commit", "try-repo", ".", "mdformat", "--files", "README.md"], +] + +[tool.tox.env."cli"] +description = "run mdformat's own CLI" +commands = [ + ["mdformat", { replace = "posargs", extend = true }], +] + +[tool.tox.env."docs"] +description = "invoke sphinx-build to build the HTML docs" +skip_install = true +deps = [ + "-r docs/requirements.txt", +] +commands = [ + ["sphinx-build", "-d", "{toxworkdir}/docs_doctree", "docs/", "{toxworkdir}/docs_out", "-W", "-b", "html", { replace = "posargs", extend = true }], + ["python", "-c", 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'], +] + +[tool.tox.env."fuzz"] +description = 'run the fuzzer (needs "apt install clang")' +deps = [ + "-r fuzzer/requirements.txt", +] +allowlist_externals = [ + "mkdir", + "cp", +] +commands = [ # Create a folder for persistent corpus and use README.md as initial seed - mkdir -p {toxworkdir}/fuzzer-corpus - cp -n README.md {toxworkdir}/fuzzer-corpus/README.md + ["mkdir", "-p", "{toxworkdir}/fuzzer-corpus"], + ["cp", "-n", "README.md", "{toxworkdir}/fuzzer-corpus/README.md"], # Run fuzzer - python fuzzer/fuzz.py {toxworkdir}/fuzzer-corpus {posargs:-len_control=10000} -''' + ["python", "fuzzer/fuzz.py", "{toxworkdir}/fuzzer-corpus", { replace = "posargs", default = ["-len_control=10000"], extend = true }], +] [tool.coverage.run] From 60fdfafc5434f55f3d0d8b17bbe4464478ae8058 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:06:19 +0300 Subject: [PATCH 2/2] Fix basepython --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 573cefe..efd9064 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,7 @@ commands = [ [tool.tox.env."mypy"] description = "run mypy" -basepython = "python3.11" +basepython = ["python3.11"] deps = [ "-r tests/requirements.txt", "mypy==1.11.2",