-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
177 lines (142 loc) · 4.51 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""Provide executable sessions for project automation."""
import nox
from nox_poetry import Session, session
nox.options.stop_on_first_error = True
nox.options.error_on_external_run = True
nox.options.sessions = "formatting", "linting", "typechecking", "testing"
python_versions = ["3.10", "3.9", "3.8", "3.7"]
locations = "src", "tests", "noxfile.py", "docs/conf.py"
@session(python=python_versions)
def testing(session: Session) -> None:
"""Run the test suite (using pytest)."""
args = session.posargs or ["--cov", "--spec"]
session.install("pytest", "pytest-cov", "pytest-spec", "expects", ".")
session.run("pytest", *args)
@session
def linting(session: Session) -> None:
"""Run linting checks (using flake8)."""
args = session.posargs or locations
session.install(
"autoflake",
"darglint",
"flake8",
"flake8-html",
"flake8-2020",
"flake8-alphabetize",
"flake8-annotations",
"flake8-annotations-complexity",
"flake8-annotations-coverage",
"flake8-bandit",
"flake8-black",
"flake8-broken-line",
"flake8-bugbear",
"flake8-builtins",
"flake8-coding",
"flake8-cognitive-complexity",
"flake8-commas",
"flake8-comprehensions",
"flake8-eradicate",
"flake8-expression-complexity",
"flake8-docstrings",
"flake8-functions",
"flake8-multiline-containers",
"flake8-mutable",
"flake8-printf-formatting",
"flake8-pytest-style",
"flake8-quotes",
"flake8-return",
"flake8-simplify",
"flake8-string-format",
"flake8-use-fstring",
"flake8-variables-names",
"pep8-naming",
)
session.run(
"autoflake",
"--recursive",
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variables",
"src/quendor/",
"tests/",
)
session.run("flake8", "--format=html", *args)
@session
def formatting(session: Session) -> None:
"""Run formatter (using black)."""
args = session.posargs or locations
session.install("black")
session.run("black", *args)
@session
def typechecking(session: Session) -> None:
"""Run type checks (using mypy)."""
args = session.posargs or locations
session.install("types-colorama", "mypy")
session.run("mypy", "--install-types", "--non-interactive", *args)
@session
def safety(session: Session) -> None:
"""Run security checks (using safety)."""
requirements = session.poetry.export_requirements()
session.install("safety")
session.run("safety", "check", "--full-report", f"--file={requirements}")
@session
def documenting(session: Session) -> None:
"""Run the documentation generator (using Sphinx)."""
session.install(".", "sphinx", "sphinx-autodoc-typehints")
session.run("sphinx-build", "docs", "docs/_build")
@session
def cleanup(session: Session) -> None:
"""Clean up generated files and directories."""
session.run(
"python",
"-c",
"import os; os.remove('.coverage') if os.path.exists('.coverage') else None",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./dist', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./htmllint', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./htmlcov', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./docs/_build', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./.mypy_cache', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./.pytest_cache', ignore_errors=True)",
)
session.run(
"python",
"-c",
"import pathlib; [p.unlink() for p in pathlib.Path('.').rglob('*.py[co]') if not str(p).startswith('.nox')]", # noqa: B950, E501
)
session.run(
"python",
"-c",
"import pathlib; [p.rmdir() for p in pathlib.Path('.').rglob('__pycache__') if not str(p).startswith('.nox')]", # noqa: B950, E501
)
@session
def clean_nox_vm(session: Session) -> None:
"""Clean up generated Nox virtual environments."""
session.run(
"python",
"-c",
"import shutil; shutil.rmtree('./.nox', ignore_errors=True)",
)