Repository navigation
Expand file tree
/
Copy pathnoxfile.py
More file actions
98 lines (77 loc) · 2.24 KB
/
Copy pathnoxfile.py
File metadata and controls
98 lines (77 loc) · 2.24 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
87
88
89
90
91
92
93
94
95
96
97
98
from __future__ import annotations
import os
import shutil
from pathlib import Path
import nox
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = (
"3.10",
"3.11",
"3.12",
"3.13",
"3.14",
)
def cargo(session: nox.Session, *args: str) -> None:
session.run("cargo", *args, external=True)
def install(
session: nox.Session,
*,
groups: str | tuple[str, ...] | None = None,
) -> None:
args: list[str] = []
if groups:
if isinstance(groups, str):
args += ["--group", groups]
elif isinstance(groups, tuple):
for group in groups:
args += ["--group", group]
session.run_install(
"uv",
"sync",
"--locked",
"--no-default-groups",
"--reinstall",
*args,
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
@nox.session(venv_backend=None, default=False)
def clean(session: nox.Session) -> None:
cargo(session, "clean")
paths = (
"./.mypy_cache",
"./.pytest_cache",
"./.ruff_cache",
"./dist",
"./tests/__pycache__",
"./__pycache__",
"./python/__pycache__",
"./.nox",
)
for p in paths:
try:
shutil.rmtree(p)
except FileNotFoundError:
pass
@nox.session(python="3.13")
def lint(session: nox.Session) -> None:
install(session, groups="lint")
session.run("mypy")
session.run("python", "-m", "mypy.stubtest", "atomicwriter")
if os.getenv("CI"):
# Do not modify files in CI, simply fail.
cargo(session, "fmt", "--check")
cargo(session, "clippy")
session.run("ruff", "check", ".")
session.run("ruff", "format", ".", "--check")
else:
# Fix any fixable errors if running locally.
cargo(session, "fmt")
cargo(session, "clippy", "--fix", "--lib", "-p", "atomicwriter")
session.run("ruff", "check", ".", "--fix")
session.run("ruff", "format", ".")
@nox.session(python=PYTHON_VERSIONS)
def tests(session: nox.Session) -> None:
install(session, groups="test")
session.run("pytest", *session.posargs)
for pyd in Path("./python/atomicwriter/").glob("*.pyd"):
pyd.unlink(missing_ok=True)