Skip to content
Snippets Groups Projects

Draft: Add pre-commit hook and improve with better linting

Closed Hannes Feldt requested to merge add-pre-commit-improve-tox-setup into main
2 files
+ 65
65
Compare changes
  • Side-by-side
  • Inline

Files

@@ -62,3 +62,68 @@ exclude = [
@@ -62,3 +62,68 @@ exclude = [
[tool.ruff.lint]
[tool.ruff.lint]
ignore = ["E203"]
ignore = ["E203"]
 
 
[tool.tox]
 
# Generative environment list to test all supported Python versions
 
requires = ["tox>=4.21"]
 
env_list = ["fix", "coverage", "lint", "format", "py{13, 12, 11, 10}"]
 
requires = ["tox-ignore-env-name-mismatch >= 0.2.0"]
 
 
[tool.tox.env_run_base]
 
package = "editable"
 
deps = [
 
"-r{toxinidir}/requirements.txt",
 
"-r{toxinidir}/tests/requirements.txt"]
 
set_env = { LANGUAGE = "en_US", LC_ALL = "en_US.UTF-8", PYTHONWARNINGS = "default::DeprecationWarning", DYNAMIC_VERSION_SOURCE= "{toxinidir}" }
 
commands = [["python", "--version"], ["python", "-m", "pytest", "tests/{posargs}"]]
 
 
[tool.tox.env.fix]
 
description = "format the code base to adhere to our styles, and complain about what we cannot do automatically"
 
skip_install = true
 
deps = ["pre-commit-uv>=4.1.1"]
 
commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure"]]
 
 
[tool.tox.env.coverage]
 
commands = [
 
["python", "--version"],
 
["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}", "tests/{posargs}"]]
 
 
# Command prefixes to reuse the same virtualenv for all linting jobs.
 
[tool.tox.env.lint]
 
deps = [
 
"ruff",
 
"-r{toxinidir}/tests/requirements.txt"]
 
commands = [
 
["python", "-m", "ruff", "--version"],
 
["python", "-m", "ruff", "check", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
 
]
 
 
[tool.tox.env.format]
 
deps = [
 
"ruff",
 
"-r{toxinidir}/tests/requirements.txt"]
 
commands = [
 
["python", "-m", "ruff", "format", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }]
 
]
 
 
[tool.tox.env.docs]
 
deps = [
 
"-r{toxinidir}/requirements.txt",
 
"-r{toxinidir}/docs/requirements.txt"]
 
# unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise
 
set_env = ""
 
changedir = "{tox_root}"
 
commands = [
 
["python", "docs/cleanup.py"],
 
["sphinx-build", "-b", "html", "docs/source", "docs/build/html"]
 
]
 
 
[tool.tox.env.build-local]
 
package = "wheel"
 
deps = ["-r{toxinidir}/build-requirements.txt"]
 
commands = [["python", "-m", "build"]]
 
 
[tool.tox.env.build-ci-linux]
 
package = "wheel"
 
deps = ["-r{toxinidir}/build-requirements.txt"]
 
commands = [["python", "-m", "cibuildwheel", "--platform", "linux", "--output-dir", "dist"]]
Loading