-
Notifications
You must be signed in to change notification settings - Fork 2
/
noxfile.py
133 lines (116 loc) · 3.27 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
"""Nox session configuration."""
import os
from typing import Any, List
import nox
from nox.sessions import Session
PACKAGE: str = "lta"
LOCATIONS: List[str] = [
PACKAGE,
"noxfile.py",
"tests",
]
VERSIONS: List[str] = [
"3.8",
"3.9",
"3.10",
]
nox.options.stop_on_first_error = False
nox.options.reuse_existing_virtualenvs = True
def constrained_install(
session: Session, *args: str, **kwargs: Any # noqa: ANN401
) -> None:
"""Install packages with poetry version constraint."""
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
"--output=requirements.txt",
external=True,
)
session.install("--constraint=requirements.txt", *args, **kwargs)
os.remove("requirements.txt")
@nox.session(python="3.10")
def form(session: Session) -> None:
"""Format code with isort and black."""
args = session.posargs or LOCATIONS
constrained_install(session, "isort", "black")
session.run("isort", *args)
session.run("black", *args)
@nox.session(python=VERSIONS)
def lint(session: Session) -> None:
"""Lint files with flake8."""
args = session.posargs or LOCATIONS
constrained_install(
session,
"flake8",
"pyproject-flake8",
"flake8-annotations",
"flake8-bandit",
"flake8-bugbear",
"flake8-comprehensions",
"flake8-docstrings",
"flake8-pytest-style",
"flake8-spellcheck",
"darglint",
)
session.run("pflake8", *args)
@nox.session(python=VERSIONS)
def type(session: Session) -> None:
"""Type check files with mypy."""
args = session.posargs or LOCATIONS
constrained_install(
session,
"mypy",
)
session.run("mypy", "--ignore-missing-imports", *args)
@nox.session(python="3.10")
def security(session: Session) -> None:
"""Check security safety."""
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
"--output=requirements.txt",
external=True,
)
session.install("--constraint=requirements.txt", "safety")
session.run(
"safety", "check", "--file=requirements.txt", "--full-report", "--ignore=44715"
)
os.remove("requirements.txt")
@nox.session(python=VERSIONS, reuse_venv=False)
def tests(session: Session) -> None:
"""Run the test suite with pytest."""
args = session.posargs or []
session.run("poetry", "install", "--no-dev", external=True)
constrained_install( # These are required for tests. Don't clutter w/ all dependencies!
session,
"coverage",
"tomli",
"pytest",
"pytest-clarity",
"pytest-sugar",
"pytest-mock",
"pytest-cov",
"pytest-xdist",
"xdoctest",
)
session.run("pytest", *args)
@nox.session(python="3.10", reuse_venv=False)
def doc(session: Session) -> None:
"""Build the documentation."""
session.run("poetry", "install", "--no-dev", external=True)
constrained_install(
session,
"sphinx",
"sphinx-rtd-theme",
"myst-parser",
"pytest",
"pytest-mock",
)
session.run("sphinx-build", "docs", "docs/_build")