-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
64 lines (49 loc) · 1.85 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Developer task automation."""
import os
import nox
nox.options.sessions = [
"check_code_formatting",
"check_types",
"run_tests",
]
PYTHON = ["3.12"]
@nox.session(python=PYTHON, reuse_venv=True)
def run_tests(session: nox.Session):
"""Run unit tests."""
session.install(".[dev]")
pytest_args = session.posargs if session.posargs else []
session.run("pytest", *pytest_args)
@nox.session(python=PYTHON, reuse_venv=True)
def format_code(session: nox.Session):
"""Lint code and re-format where necessary."""
session.install(".[dev]")
session.run("black", "--config=pyproject.toml", ".")
session.run("ruff", "check", ".", "--config=pyproject.toml", "--fix")
@nox.session(python=PYTHON, reuse_venv=True)
def check_code_formatting(session: nox.Session):
"""Check code for formatting errors."""
session.install(".[dev]")
session.run("black", "--config=pyproject.toml", "--check", ".")
session.run("ruff", "check", ".", "--config=pyproject.toml")
@nox.session(python=PYTHON, reuse_venv=True)
def check_types(session: nox.Session):
"""Run static type checking."""
session.install(".[dev]")
session.run("mypy")
@nox.session(python=PYTHON, reuse_venv=True)
def build_and_deploy(session: nox.Session):
"""Build wheel and deploy to PyPI."""
try:
from dotenv import load_dotenv
load_dotenv()
except ModuleNotFoundError:
session.warn("Expecting PYPI_USR and PYPI_PWD in local environment variables.")
try:
PYPI_USR = os.environ["PYPI_USR"]
PYPI_PWD = os.environ["PYPI_PWD"]
except KeyError as e:
session.error(f"{str(e)} not found in local environment variables.")
session.install(".[deploy]")
session.run("rm", "-rf", "dist")
session.run("python", "-m", "build")
session.run("twine", "upload", "dist/*", "-u", PYPI_USR, "-p", PYPI_PWD)