forked from ansatzcapital/dilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
116 lines (86 loc) · 3.22 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
"""Nox setup.
To run all linters, checkers, and tests:
nox
To run all fixers:
nox -t fix
By default, nox will set up venvs for each session. To use your current
env instead, add `--no-venv` to any command:
nox --no-venv
By default, nox will recreate venvs for each session. To reuse your existing
env instead, add `--reuse`/`-r` to any command:
nox --reuse
To run all static linters and checkers:
nox -t static
To pick a particular session, e.g.:
nox --list
nox -s fix_ruff
nox -s pytest -- -k test_name
To do an editable install into your current env:
nox -s develop
See https://nox.thea.codes/en/stable/index.html for more.
"""
import sys
import nox
import nox.virtualenv
# Hack to fix tags for non-defaulted sessions (otherwise, running
# `nox -t fix` won't pick up any sessions)
if any(arg.startswith("fix") for arg in sys.argv):
nox.options.sessions = ["fix_ruff"]
else:
nox.options.sessions = ["ruff", "mypy", "pyright", "pytest"]
def is_isolated_venv(session: nox.Session) -> bool:
"""Indicates that the session is being run in an isolated env.
I.e., the user has not set `--no-venv`.
If the user uses their development (non-isolated) venv,
then nox will (correctly) refuse to install packages, unless forced to.
"""
return not isinstance(session.virtualenv, nox.virtualenv.PassthroughEnv)
@nox.session(tags=["static", "typecheck"])
def mypy(session: nox.Session) -> None:
if is_isolated_venv(session):
session.install("-e", ".[test]")
session.run("mypy", "dilib")
@nox.session(tags=["static", "typecheck"])
def pyright(session: nox.Session) -> None:
# TODO: Remove once pyright >= 1.1.387 is available. See:
# - https://github.com/microsoft/pyright/issues/9296
# - https://docs.python.org/3/library/sys.html#sys.platform
if sys.platform == "win32":
session.install("pyright <= 1.1.385")
if is_isolated_venv(session):
session.install("-e", ".[test]")
env = {"PYRIGHT_PYTHON_VERBOSE": "1"}
# Enable for debugging
if False:
env["PYRIGHT_PYTHON_DEBUG"] = "1"
session.run("pyright", "dilib", env=env)
@nox.session(tags=["test"])
def pytest(session: nox.Session) -> None:
if is_isolated_venv(session):
session.install("-e", ".[test]")
session.run("pytest", "dilib", *session.posargs)
@nox.session(tags=["lint", "static"])
def ruff(session: nox.Session) -> None:
if is_isolated_venv(session):
session.install("-e", ".[test]")
session.run("ruff", "format", "dilib", "--check")
session.run("ruff", "check", "dilib")
@nox.session(tags=["fix"])
def fix_ruff(session: nox.Session) -> None:
if is_isolated_venv(session):
session.install("-e", ".[test]")
session.run("ruff", "format", "dilib")
session.run("ruff", "check", "dilib", "--fix")
@nox.session(venv_backend="none")
def develop(session: nox.Session) -> None:
# We install using compatibility mode for VS Code
# to pick up the installation correctly.
# See https://setuptools.pypa.io/en/latest/userguide/development_mode.html#legacy-behavior.
session.run(
"pip",
"install",
"-e",
".[setup,test]",
"--config-settings",
"editable_mode=compat",
)