Repository navigation
Expand file tree
/
Copy pathnoxfile.py
More file actions
executable file
·86 lines (66 loc) · 2 KB
/
Copy pathnoxfile.py
File metadata and controls
executable file
·86 lines (66 loc) · 2 KB
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
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "nox==2025.5.1",
# ]
# ///
# SPDX-License-Identifier: MIT
from __future__ import annotations
from collections.abc import Sequence
from typing import Any
import nox
nox.needs_version = ">=2025.5.1"
nox.options.error_on_external_run = True
nox.options.default_venv_backend = "uv|virtualenv"
nox.options.reuse_venv = "yes"
PYPROJECT = nox.project.load_toml()
def install_deps(
session: nox.Session,
*,
extras: Sequence[str] = (),
groups: Sequence[str] = (),
project: bool = True,
) -> None:
"""Helper to install dependencies from a group."""
if not project and extras:
msg = "Cannot install extras without also installing the project"
raise TypeError(msg)
command: list[str] = [
"uv",
"sync",
"--no-default-groups",
]
env: dict[str, Any] = {}
if session.venv_backend != "none":
command.append(f"--python={session.virtualenv.location}")
env["UV_PROJECT_ENVIRONMENT"] = str(session.virtualenv.location)
if extras:
command.extend([f"--extra={e}" for e in extras])
if groups:
command.extend([f"--group={g}" for g in groups])
if not project:
command.append("--no-install-project")
session.run_install(
*command,
env=env,
external=True,
)
@nox.session
def lint(session: nox.Session) -> None:
"""Check all files for linting errors."""
install_deps(session, project=False, groups=["tools"])
session.run("prek", "run", "--all-files", *session.posargs)
@nox.session
def pyright(session: nox.Session) -> None:
"""Run pyright."""
install_deps(session, project=False, groups=["nox", "typing"])
env = {
"PYRIGHT_PYTHON_IGNORE_WARNINGS": "1",
}
try:
session.run("python", "-m", "pyright", *session.posargs, env=env)
except KeyboardInterrupt:
session.error("Interrupted!")
if __name__ == "__main__":
nox.main()