From 53b97f3131612f7512d71253df8200e4f9f09257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Paduszy=C5=84ski?= <92403542+paduszyk@users.noreply.github.com> Date: Wed, 22 May 2024 21:54:38 +0200 Subject: [PATCH] chore: install, lint, and test package with Nox (#10) --- .gitignore | 3 ++ docs/README.md | 2 + noxfile.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 ++ 4 files changed, 119 insertions(+) create mode 100644 noxfile.py diff --git a/.gitignore b/.gitignore index 59af6af..653c2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ coverage.xml # Environment variables .env + +# Nox +.nox/ diff --git a/docs/README.md b/docs/README.md index 36f5f4a..e917489 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,6 +2,7 @@ [![Pre-commit](https://img.shields.io/github/actions/workflow/status/paduszyk/django-xlsx-serializer/pre-commit-run.yml?style=flat-square&label=pre-commit&logo=pre-commit)][pre-commit] +[![Nox](https://img.shields.io/badge/%F0%9F%A6%8A-Nox-D85E00.svg?style=flat-square)][nox] [![Ruff](https://img.shields.io/endpoint?style=flat-square&url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)][ruff] [![Mypy](https://img.shields.io/badge/type--checked-mypy-blue?style=flat-square&logo=python)][mypy] [![Prettier](https://img.shields.io/badge/code%20style-prettier-1E2B33?style=flat-square&logo=Prettier)][prettier] @@ -18,6 +19,7 @@ Released under the [MIT license][license]. [conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/ [license]: https://github.com/paduszyk/django-xlsx-serializer/blob/main/LICENSE [mypy]: https://mypy.readthedocs.io +[nox]: https://github.com/wntrblm/nox [paduszyk]: https://github.com/paduszyk [pre-commit]: https://github.com/paduszyk/django-xlsx-serializer/actions/workflows/pre-commit-run.yml [prettier]: https://prettier.io diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..059b93e --- /dev/null +++ b/noxfile.py @@ -0,0 +1,111 @@ +from __future__ import annotations + +from itertools import chain + +import nox + +PYTHON_VERSIONS = [ + "3.9", + "3.10", + "3.11", + "3.12", +] + +DJANGO_VERSIONS = { + "3.9": ["3.2", "4.0", "4.1", "4.2"], + "3.10": ["3.2", "4.0", "4.1", "4.2", "5.0"], + "3.11": ["4.1", "4.2", "5.0"], + "3.12": ["4.2", "5.0"], +} + +DATABASE_ENGINES = [ + "postgresql", + "sqlite3", +] + +RUFF_CHECK_OPTIONS = [ + "--output-format=github", +] + +RUFF_FORMAT_OPTIONS = [ + "--diff", +] + +MYPY_OPTIONS = [ + "--install-types", + "--non-interactive", +] + +PYTEST_OPTIONS = [ + "-ra", + "-vv", +] + + +# Nox +# https://nox.thea.codes/ + + +@nox.session(tags=["install"]) +@nox.parametrize("python", PYTHON_VERSIONS) +def install(session: nox.Session) -> None: + session.install(".") + + +@nox.session(tags=["lint"]) +def ruff_lint(session: nox.Session) -> None: + session.install("ruff") + + session.run("ruff", "check", *RUFF_CHECK_OPTIONS, ".") + + +@nox.session(tags=["lint"]) +def ruff_format(session: nox.Session) -> None: + session.install("ruff") + + session.run("ruff", "format", *RUFF_FORMAT_OPTIONS, ".") + + +@nox.session(tags=["lint"]) +def mypy(session: nox.Session) -> None: + session.install("-e", ".") + session.install( + "django-stubs[compatible-mypy] < 6", + "psycopg2-binary < 3", + "python-dotenv < 2", + ) + + session.run("mypy", *MYPY_OPTIONS, ".") + + +@nox.session(tags=["test"]) +@nox.parametrize("database_engine", DATABASE_ENGINES) +@nox.parametrize( + ("python", "django"), + chain.from_iterable( + [ + (python_version, django_version) + for django_version in DJANGO_VERSIONS[python_version] + ] + for python_version in PYTHON_VERSIONS + ), +) +def pytest(session: nox.Session, django: str, database_engine: str) -> None: + session.install(f"django == {django}.*") + session.install("-e", ".") + session.install( + "psycopg2-binary < 3", + "pytest < 9", + "pytest-cov", + "pytest-custom-exit-code < 1", + "pytest-django < 5", + "python-dotenv < 2", + ) + + session.run( + "pytest", + *PYTEST_OPTIONS, + env={ + "DATABASE_ENGINE": database_engine, + }, + ) diff --git a/pyproject.toml b/pyproject.toml index c761418..0dd7212 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ "django-stubs[compatible-mypy] < 6", + "nox", "pre-commit < 4", "pytest < 9", "pytest-cov < 6", @@ -123,12 +124,14 @@ plugins = [ [[tool.mypy.overrides]] module = [ + "nox", "pytest", ] ignore_missing_imports = true [[tool.mypy.overrides]] module = [ + "noxfile", "tests.*", ] disallow_untyped_decorators = false