2022-03-28 16:22:18 +02:00
|
|
|
"""Nox configuration file"""
|
|
|
|
from os import fsdecode
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import nox
|
|
|
|
from nox import Session
|
|
|
|
|
|
|
|
nox.options.sessions = ["checks"]
|
|
|
|
|
|
|
|
LINT_PATHS = ["frontools", "tests"]
|
|
|
|
PYTEST_PACKAGES = ["pytest", "pytest-cov", "pytest-datadir"]
|
2022-03-28 16:52:56 +02:00
|
|
|
POETRY_PACKAGES = ["poetry", "poetry-dynamic-versioning"]
|
2022-03-28 16:22:18 +02:00
|
|
|
VENV_DIR = Path(".venv")
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python=["3.9", "3.10"], reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def tests(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run unit tests."""
|
|
|
|
session.install("-e", ".", *PYTEST_PACKAGES)
|
|
|
|
session.run("pytest")
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def black(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Check black formatting."""
|
|
|
|
session.install("black")
|
|
|
|
session.run("black", "--check", *LINT_PATHS)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def flake8(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run flake8"""
|
|
|
|
session.install("flake8")
|
2022-03-30 02:19:02 +02:00
|
|
|
session.run("flake8", "frontools", "tests")
|
2022-03-28 16:22:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@nox.session(reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def isort(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Check imports sorting"""
|
|
|
|
session.install("isort")
|
|
|
|
session.run("isort", "--check", *LINT_PATHS)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def mypy(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run Mypy"""
|
2022-04-11 17:31:16 +02:00
|
|
|
session.install("mypy", "types-pyyaml", "types-click", "-e", ".")
|
2022-03-30 02:19:02 +02:00
|
|
|
session.run("mypy", "--install-types", *LINT_PATHS)
|
2022-03-28 16:22:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@nox.session(reuse_venv=True)
|
2022-03-30 02:19:02 +02:00
|
|
|
def pylint(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run pylint"""
|
|
|
|
session.install("pylint", "-e", ".", *PYTEST_PACKAGES)
|
|
|
|
session.run("pylint", "--rcfile=pyproject.toml", *LINT_PATHS)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python=False)
|
2022-03-30 02:19:02 +02:00
|
|
|
def lint(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run all lint tasks"""
|
|
|
|
session.notify("black")
|
|
|
|
session.notify("flake8")
|
|
|
|
session.notify("isort")
|
|
|
|
session.notify("mypy")
|
|
|
|
session.notify("pylint")
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python=False)
|
2022-03-30 02:19:02 +02:00
|
|
|
def checks(session: Session) -> None:
|
2022-03-28 16:22:18 +02:00
|
|
|
"""Run all checks"""
|
|
|
|
session.notify("lint")
|
|
|
|
session.notify("tests")
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python=False)
|
|
|
|
def dev(session: Session) -> None:
|
|
|
|
"""
|
|
|
|
Sets up a python development environment for the project.
|
|
|
|
"""
|
|
|
|
|
|
|
|
session.run(
|
|
|
|
"python3",
|
|
|
|
"-m",
|
|
|
|
"virtualenv",
|
|
|
|
"-p",
|
|
|
|
"python3.10",
|
|
|
|
fsdecode(VENV_DIR),
|
|
|
|
silent=True,
|
|
|
|
)
|
|
|
|
python_path = Path.cwd() / VENV_DIR / "bin/python"
|
|
|
|
python = fsdecode(python_path)
|
|
|
|
session.run(
|
2022-03-28 16:52:56 +02:00
|
|
|
python, "-m", "pip", "install", *POETRY_PACKAGES, external=True, silent=True
|
2022-03-28 16:22:18 +02:00
|
|
|
)
|
2022-03-28 16:52:56 +02:00
|
|
|
session.run(python, "-m", "poetry", "install", external=True, silent=True)
|
2022-03-28 16:22:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python="3.10")
|
|
|
|
def publish(session: Session) -> None:
|
|
|
|
"""
|
|
|
|
Publish a package to pypi
|
|
|
|
"""
|
|
|
|
|
2022-03-28 16:52:56 +02:00
|
|
|
session.install(*POETRY_PACKAGES)
|
2022-03-28 16:22:18 +02:00
|
|
|
session.run("poetry", "publish", "--build")
|