-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
76 lines (58 loc) · 1.93 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
import os
import shutil
from pathlib import Path
import nox
nox.needs_version = ">=2024.10.9"
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = ("3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10", "pypy3.11")
def cargo(session: nox.Session, *args: str) -> None:
session.run("cargo", *args, external=True)
def install(session: nox.Session) -> None:
session.run_install(
"uv",
"sync",
"--locked",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.run("maturin", "develop", "--uv")
@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)
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", "--allow-dirty")
session.run("ruff", "check", ".", "--fix")
session.run("ruff", "format", ".")
@nox.session(python=PYTHON_VERSIONS)
def tests(session: nox.Session) -> None:
install(session)
session.run("pytest", *session.posargs)
for pyd in Path("./python/atomicwriter/").glob("*.pyd"):
pyd.unlink(missing_ok=True)