forked from MongoEngine/flask-mongoengine
-
Notifications
You must be signed in to change notification settings - Fork 4
/
noxfile.py
151 lines (127 loc) · 4.44 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
"""Nox tool configuration file.
Nox is Tox tool replacement.
"""
import shutil
from pathlib import Path
import nox
nox.options.sessions = "latest", "lint", "documentation_tests"
def base_install(session, flask, mongoengine, toolbar, wtf):
"""Create basic environment setup for tests and linting."""
session.run("python", "-m", "pip", "install", "--upgrade", "pip")
session.run("python", "-m", "pip", "install", "setuptools_scm[toml]>=6.3.1")
if toolbar and wtf:
extra = "wtf,toolbar,"
elif toolbar:
extra = "toolbar,"
elif wtf:
extra = "wtf,"
else:
extra = ""
if flask == "==1.1.4":
session.install(
f"Flask{flask}",
f"mongoengine{mongoengine}",
"-e",
f".[{extra}legacy,legacy-dev]",
)
elif flask == "==2.0.3":
session.install(
f"Flask{flask}",
f"mongoengine{mongoengine}",
"werkzeug==2.2.3",
"-e",
f".[{extra}dev]",
)
else:
session.install(
f"Flask{flask}",
f"mongoengine{mongoengine}",
"-e",
f".[{extra}dev]",
)
return session
@nox.session(python="3.10")
def lint(session):
"""Run linting check locally."""
session.install("pre-commit")
session.run("pre-commit", "run", "-a")
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.parametrize("flask", ["==1.1.4", "==2.0.3", "==2.3.3", ">=3.0.0"])
@nox.parametrize("mongoengine", ["==0.21.0", "==0.22.1", "==0.23.1", ">=0.24.1"])
@nox.parametrize("toolbar", [True, False])
@nox.parametrize("wtf", [True, False])
def ci_cd_tests(session, flask, mongoengine, toolbar, wtf):
"""Run test suite with pytest into ci_cd (no docker)."""
session = base_install(session, flask, mongoengine, toolbar, wtf)
session.run("pytest", *session.posargs)
def _run_in_docker(session, db_version="5.0"):
session.run(
"docker",
"run",
"--name",
"nox_docker_test",
"-p",
"27017:27017",
"-d",
f"mongo:{db_version}",
external=True,
)
try:
session.run("pytest", *session.posargs)
finally:
session.run_always("docker", "rm", "-fv", "nox_docker_test", external=True)
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.parametrize("flask", ["==1.1.4", "==2.0.3", "==2.3.3", ">=3.0.0"])
@nox.parametrize("mongoengine", ["==0.21.0", "==0.22.1", "==0.23.1", ">=0.24.1"])
@nox.parametrize("toolbar", [True, False])
@nox.parametrize("wtf", [True, False])
@nox.parametrize("db_version", ["5.0", "6.0", "7.0"])
def full_tests(session, flask, mongoengine, toolbar, wtf, db_version):
"""Run tests locally with docker and complete support matrix."""
session = base_install(session, flask, mongoengine, toolbar, wtf)
_run_in_docker(session, db_version)
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.parametrize("toolbar", [True, False])
@nox.parametrize("wtf", [True, False])
@nox.parametrize("db_version", ["5.0", "6.0", "7.0"])
def latest(session, toolbar, wtf, db_version):
"""Run minimum tests for checking minimum code quality."""
flask = ">=3.0.0"
mongoengine = ">=0.24.1"
session = base_install(session, flask, mongoengine, toolbar, wtf)
if session.interactive:
_run_in_docker(session, db_version)
else:
session.run("pytest", *session.posargs)
@nox.session(python="3.10")
def documentation_tests(session):
"""Run documentation tests."""
return docs(session, batch_run=True)
@nox.session(python="3.10")
def docs(session, batch_run: bool = False):
"""Build the documentation or serve documentation interactively."""
shutil.rmtree(Path("docs").joinpath("_build"), ignore_errors=True)
session.install("-r", "docs/requirements.txt")
session.install("-e", ".[wtf,toolbar]")
session.cd("docs")
sphinx_args = ["-b", "html", "-W", ".", "_build/html"]
if not session.interactive or batch_run:
sphinx_cmd = "sphinx-build"
else:
sphinx_cmd = "sphinx-autobuild"
sphinx_args.extend(
[
"--open-browser",
"--port",
"9812",
"--watch",
"../*.md",
"--watch",
"../*.rst",
"--watch",
"../*.py",
"--watch",
"../flask_mongoengine",
]
)
session.run(sphinx_cmd, *sphinx_args)