-
Notifications
You must be signed in to change notification settings - Fork 4
/
noxfile.py
163 lines (117 loc) · 5.21 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
"""Packaging, testing and release process automation API.
The automation is build using `nox` (https://nox.thea.codes/en/stable/).
Quick guide:
To run all the sessions:
>>> nox
To run only the code-quality check tagged session:
>>> nox -t quality
To run only the unit-test tagged session:
>>> nox -t tests
To run a session (fmt, lint, check, test):
>>> nox -s {fmt,lint,check,test}
To run a session and pass extra arguments:
>>> nox -s test -- tests/eva/metrics/test_average_loss.py
"""
import os
import nox
PYTHON_VERSIONS = ["3.10"]
"""The python versions to test on."""
LOCATIONS = "src", "tests", "noxfile.py"
"""The locations to add to nox."""
nox.options.sessions = "fmt", "lint", "check", "test"
"""List of all available sessions."""
nox.options.reuse_existing_virtualenvs = True
"""Whether to re-use the virtualenvs between runs."""
nox.options.stop_on_first_error = True
"""Whether to abort as soon as the first session fails."""
# so that PDM pick up the Python in the virtualenv correctly
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"})
# unexpected behavior in some cases due to __pypackages__
os.environ.pop("PYTHONPATH", None)
@nox.session(tags=["fmt", "format", "quality"])
def fmt(session: nox.Session) -> None:
"""Formats the source code format."""
args = session.posargs or LOCATIONS
session.run_always("pdm", "install", "--no-default", "--group", "lint", external=True)
session.run("isort", *args)
session.run("black", *args)
session.run("ruff", "check", "--fix-only", *args)
@nox.session(tags=["lint", "quality"])
def lint(session: nox.Session) -> None:
"""Checks the source code for programmatic, stylistic and security violations."""
args = session.posargs or LOCATIONS
session.run_always("pdm", "install", "--no-default", "--group", "lint", external=True)
session.run("isort", "--check-only", *args)
session.run("black", "--check", *args)
session.run("ruff", "check", *args)
session.run("yamllint", *args)
session.run("bandit", "-q", "-c", "pyproject.toml", "-r", *args)
@nox.session(tags=["check", "quality"])
def check(session: nox.Session) -> None:
"""Performs statically type checking of the source code."""
args = session.posargs or LOCATIONS
session.run_always("pdm", "install", "--group", "typecheck", "--group", "all", external=True)
session.run("pyright", *args)
@nox.session(python=PYTHON_VERSIONS, tags=["unit-tests", "tests"])
def test(session: nox.Session) -> None:
"""Runs the tests and code coverage analysis session of all the source code."""
session.notify("test_core")
session.notify("test_vision")
@nox.session(python=PYTHON_VERSIONS, tags=["unit-tests", "tests"])
def test_core(session: nox.Session) -> None:
"""Runs the tests and code coverage analysis session of the core source code."""
args = session.posargs or ["--cov"]
session.run_always("pdm", "install", "--group", "test", external=True)
session.run("pytest", os.path.join("tests", "eva", "core"), *args)
@nox.session(python=PYTHON_VERSIONS, tags=["unit-tests", "tests"])
def test_vision(session: nox.Session) -> None:
"""Runs the tests and code coverage analysis session of the vision source code."""
args = session.posargs or ["--cov"]
session.run_always("pdm", "install", "--group", "test", "--group", "vision", external=True)
session.run("pytest", os.path.join("tests", "eva", "vision"), *args)
@nox.session(python=PYTHON_VERSIONS, tags=["unit-tests", "tests"])
def test_all(session: nox.Session) -> None:
"""Runs the tests and code coverage analysis session of all the source code."""
args = session.posargs or ["--cov"]
session.run_always("pdm", "install", "--group", "test", "--group", "all", external=True)
session.run("pytest", *args)
@nox.session(python=PYTHON_VERSIONS, tags=["ci"])
def ci(session: nox.Session) -> None:
"""Runs the CI workflow."""
session.notify("lint")
session.notify("check")
session.notify("test")
@nox.session
def version(session: nox.Session) -> None:
"""Fetches and prints the version of the library."""
session.run_always("pdm", "self", "add", "pdm-version", external=True)
session.run("pdm", "version", external=True)
@nox.session
def bump(session: nox.Session) -> None:
"""Bumps the version of the library.
Usage:
Update patch (0.0.1 -> 0.0.2)
>>> nox -s bump -- micro
Update minor (0.0.1 -> 0.1.0)
>>> nox -s bump -- minor
Update major (0.0.1 -> 1.0.0)
>>> nox -s bump -- minor
Update dev (0.0.1 -> 0.0.1.dev1)
>>> nox -s bump -- dev
"""
session.run_always("pdm", "self", "add", "pdm-bump", external=True)
session.run("pdm", "bump", *session.posargs, external=True)
@nox.session
def docs(session: nox.Session) -> None:
"""Builds and deploys the code documentation."""
args = session.posargs or []
session.run_always("pdm", "install", "--group", "docs", external=True)
session.run("pdm", "run", "mike", *args)
@nox.session
def build(session: nox.Session) -> None:
"""Builds the source and wheel distributions."""
session.run("pdm", "build")
@nox.session
def publish(session: nox.Session) -> None:
"""Builds and publishes the source and wheel distributions."""
session.run("pdm", "publish")