-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
163 lines (128 loc) · 5.12 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
import re
import shutil
import tomllib
from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path
from tempfile import TemporaryDirectory
import nox
# TODO check the problem
nox.options.default_venv_backend = "uv"
@contextmanager
def chdir(path: Path) -> Generator[None, None, None]:
"""Context manager to change directory."""
cwd = Path.cwd()
os.chdir(path)
try:
yield
finally:
os.chdir(cwd)
@nox.session(python=["3.9", "3.11", "3.13"])
def test_bfabric(session):
session.install("./bfabric[test]")
session.run("uv", "pip", "list")
session.run("pytest", "--durations=50", "tests/bfabric")
@nox.session(python=["3.9", "3.11", "3.13"])
def test_bfabric_scripts(session):
session.install("-e", "./bfabric_scripts[test]")
session.run("uv", "pip", "list")
packages = ["tests/bfabric_scripts"]
if session.python.split(".")[0] == "3" and int(session.python.split(".")[1]) >= 11:
packages.append("tests/bfabric_cli")
session.run("pytest", "--durations=50", *packages)
@nox.session(python=["3.13"])
def test_bfabric_app_runner(session):
session.install("-e", "./bfabric")
session.install("./bfabric_app_runner[test]")
session.run("uv", "pip", "list")
session.run("pytest", "--durations=50", "tests/bfabric_app_runner")
@nox.session
def test_py_typed(session):
"""Verify py.typed is properly installed with the package."""
session.install("./bfabric")
result = session.run(
"python",
"-c",
"import bfabric, pathlib; p=pathlib.Path(bfabric.__file__).parent/'py.typed'; print(p.exists())",
silent=True,
stderr=None,
)
if not result or result.strip() != "True":
session.error("py.typed not found in installed package")
@nox.session(default=False)
def docs(session):
"""Builds documentation for bfabricPy and app-runner and writes to site directory."""
with TemporaryDirectory() as tmpdir:
session.install("./bfabric[doc]")
with chdir("bfabric"):
session.run("mkdocs", "build", "-d", Path(tmpdir) / "build_bfabricpy")
session.install("./bfabric_app_runner[doc]")
session.run(
"sphinx-build",
"-M",
"html",
"bfabric_app_runner/docs",
Path(tmpdir) / "build_app_runner",
)
target_dir = Path("site")
if target_dir.exists():
shutil.rmtree(target_dir)
shutil.copytree(Path(tmpdir) / "build_bfabricpy", target_dir)
shutil.copytree(Path(tmpdir) / "build_app_runner" / "html", target_dir / "app_runner")
@nox.session(default=False)
def publish_docs(session):
"""Publish documentation to GitHub Pages by updating gh-pages branch."""
site_dir = Path("site")
if not site_dir.exists():
session.error("Site directory does not exist. Run 'nox -s docs' first.")
session.install("ghp-import")
session.run("ghp-import", "--force", "--no-jekyll", "--push", "site")
@nox.session(default=False)
def code_style(session):
session.install("ruff")
session.run("ruff", "check", "bfabric")
@nox.session
def licensecheck(session) -> None:
"""Runs the license check."""
# TODO is there a better way
session.install("licensecheck")
session.run("sh", "-c", "cd bfabric && licensecheck")
def verify_changelog_version(session: nox.Session, package_dir: str) -> None:
"""
Verify that the changelog contains an entry for the current version.
Args:
session: The nox session
package_dir: The package directory to check (e.g., 'bfabric', 'bfabric_scripts')
Raises:
nox.CommandFailed: If the changelog doesn't contain the current version
"""
package_path = Path(package_dir)
# Read version from pyproject.toml
try:
with open(package_path / "pyproject.toml", "rb") as f:
pyproject = tomllib.load(f)
current_version = pyproject["project"]["version"]
except (FileNotFoundError, KeyError) as e:
session.error(f"Failed to read version from pyproject.toml: {e}")
# Read and check changelog
changelog_path = package_path / "docs" / "changelog.md"
try:
changelog_content = changelog_path.read_text()
except FileNotFoundError:
session.error(f"Changelog not found at {changelog_path}")
# Look for version header with escaped brackets
version_pattern = rf"## \\\[{re.escape(current_version)}\\\]"
if not re.search(version_pattern, changelog_content):
session.error(
f"{changelog_path} does not contain entry for version {current_version}.\n"
f"Expected to find a section starting with: ## \\[{current_version}\\]"
)
session.log(f"✓ {changelog_path} contains entry for version {current_version}")
@nox.session
def check_changelog(session: nox.Session):
"""Check that changelog contains current version for all packages being released."""
# List of packages to check - could be made configurable
packages = ["bfabric", "bfabric_scripts", "bfabric_app_runner"]
for package in packages:
verify_changelog_version(session, package)