-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
128 lines (95 loc) · 3.63 KB
/
noxfile.py
File metadata and controls
128 lines (95 loc) · 3.63 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
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
from pathlib import Path
import nox
# Default sessions when running plain `nox`
nox.options.sessions = ["lint", "mypy", "tests", "docs-build"]
# Paths for project layout
PROJECT_DIR = Path("server") / "eudai"
SRC_DIR = PROJECT_DIR / "src"
TESTS_DIR = PROJECT_DIR / "tests"
DOCS_DIR = Path("docs")
@nox.session
def lint(session: nox.Session) -> None:
"""
Lint and format the backend with ruff.
"""
if not PROJECT_DIR.exists():
session.error(f"{PROJECT_DIR} does not exist. Adjust PROJECT_DIR in noxfile.py.")
session.chdir(str(PROJECT_DIR))
session.install("ruff")
# Only include tests/ if it actually exists
paths = ["src"]
if TESTS_DIR.exists():
paths.append("tests")
# Format first, then lint
session.run("ruff", "format", *paths, external=True)
session.run("ruff", "check", *paths, external=True)
@nox.session
def mypy(session: nox.Session) -> None:
"""
Type-check the backend with mypy.
"""
if not PROJECT_DIR.exists():
session.error(f"{PROJECT_DIR} does not exist. Adjust PROJECT_DIR in noxfile.py.")
session.chdir(str(PROJECT_DIR))
# Install your package + mypy
session.run("pip", "install", "-e", ".", external=True)
session.install("mypy")
# Start with main.py; include tests/ once it exists.
targets = ["src"]
if TESTS_DIR.exists():
targets.append("tests")
session.run("mypy", *targets)
@nox.session
def tests(session: nox.Session) -> None:
"""
Run the test suite with coverage.
If tests/ doesn't exist yet, this session will *skip* instead of failing.
"""
if not PROJECT_DIR.exists():
session.error(f"{PROJECT_DIR} does not exist. Adjust PROJECT_DIR in noxfile.py.")
session.chdir(str(PROJECT_DIR))
session.run("pip", "install", "-e", ".", external=True)
session.install("pytest", "coverage[toml]")
if not TESTS_DIR.exists():
session.log("No tests/ directory found; skipping tests session.")
return
# Single coverage file for now
session.env["COVERAGE_FILE"] = ".coverage"
session.run("coverage", "run", "-m", "pytest", "tests")
@nox.session(name="docs-build")
def docs_build(session: nox.Session) -> None:
"""
Build the documentation from the top-level docs/ directory.
If docs/conf.py doesn't exist yet, skip the session gracefully.
"""
if not DOCS_DIR.exists():
session.log("docs/ directory not found at repo root; skipping docs-build")
return
conf_py = DOCS_DIR / "conf.py"
if not conf_py.exists():
session.log("No docs/conf.py found; skipping docs-build session.")
return
# Install package from server/eudai into this venv
session.run("pip", "install", "-e", "server/eudai", external=True)
# Install sphinx + theme
session.install("sphinx", "sphinx-rtd-theme")
# Build docs from repo root
build_dir = DOCS_DIR / "_build"
build_dir.mkdir(parents=True, exist_ok=True)
session.run("sphinx-build", "-W", "docs", str(build_dir))
@nox.session
def coverage(session: nox.Session) -> None:
"""
Combine coverage from multiple test runs and optionally generate XML.
- `nox -s coverage` → combine & show text report
- `nox -s coverage -- xml` → combine & write coverage.xml
"""
if not PROJECT_DIR.exists():
session.error(f"{PROJECT_DIR} does not exist. Adjust PROJECT_DIR in noxfile.py.")
session.chdir(str(PROJECT_DIR))
session.install("coverage[toml]")
session.run("coverage", "combine")
if session.posargs and session.posargs[0] == "xml":
session.run("coverage", "xml")
else:
session.run("coverage", "report")