-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnoxfile.py
143 lines (124 loc) · 3.52 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
134
135
136
137
138
139
140
141
142
143
# -*- 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.9",
"3.10",
]
nox.options.stop_on_first_error = False
nox.options.reuse_existing_virtualenvs = True
def poetry_path() -> str:
"""Get the path to poetry."""
return os.environ.get("POETRY_PATH", "poetry")
def constrained_install(
session: Session, *args: str, **kwargs: Any # noqa: ANN401
) -> None:
"""Install packages with poetry version constraint."""
session.run(
poetry_path(),
"export",
"--with",
"dev",
"--without-hashes",
"--format=requirements.txt",
"--output=requirements.txt",
external=True,
)
session.install("--requirement=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_path(),
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
"--output=requirements.txt",
external=True,
)
session.install("--requirement=requirements.txt", "safety")
session.run(
"safety",
"check",
"--file=requirements.txt",
"--full-report",
"--ignore=44715",
"--ignore=51457", # https://github.com/pytest-dev/pytest/issues/10392
)
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_path(), "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_path(), "install", "--no-dev", external=True)
constrained_install(
session,
"sphinx",
"sphinx-rtd-theme",
"myst-parser",
"pytest",
"pytest-mock",
)
session.run("sphinx-build", "docs", "docs/_build")