Skip to content

Commit

Permalink
chore: install, lint, and test package with Nox (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
paduszyk authored May 22, 2024
1 parent 8490c2a commit 53b97f3
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ coverage.xml

# Environment variables
.env

# Nox
.nox/
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
111 changes: 111 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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,
},
)
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dynamic = ["version"]
[project.optional-dependencies]
dev = [
"django-stubs[compatible-mypy] < 6",
"nox",
"pre-commit < 4",
"pytest < 9",
"pytest-cov < 6",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 53b97f3

Please sign in to comment.