-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoxfile.py
More file actions
98 lines (78 loc) · 2.8 KB
/
noxfile.py
File metadata and controls
98 lines (78 loc) · 2.8 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 re
import subprocess
from pathlib import Path
import nox
DIR = Path(__file__).parent.resolve()
REPO = "agriyakhetarpal/hugo-python-distributions"
DOCS_DIR = DIR / "docs"
nox.options.sessions = ["lint"]
nox.options.default_venv_backend = "uv|virtualenv"
@nox.session
def lint(session: nox.Session) -> None:
"""
Run the linter.
"""
session.install("prek")
session.run("prek", "-a", *session.posargs)
@nox.session(name="venv", reuse_venv=True)
def venv(session: nox.Session) -> None:
"""Create a virtual environment and install wheels from a specified folder into it."""
folder = "dist" if session.interactive else "wheelhouse"
session.log(f"Installing wheels from {folder}")
for file in DIR.joinpath(folder).glob("*.whl"):
session.install(file)
session.run("hugo", "version")
session.run("hugo", "env", "--logLevel", "debug")
def _get_version(session: nox.Session) -> str:
"""Extract version from session posargs or setup.py."""
if session.posargs:
return session.posargs[0].lstrip("v")
content = (DIR / "setup.py").read_text()
match = re.search(r'HUGO_VERSION = "([0-9.]+)"', content)
if not match:
session.error("Could not determine version. Pass it as: nox -s tag -- 0.157.0")
return match.group(1)
@nox.session(default=False, reuse_venv=True)
def docs(session: nox.Session) -> None:
"""Build the documentation website.
Pass -- serve to start a live-reloading development server instead.
"""
session.install(".")
if session.posargs == ["serve"]:
session.run("hugo", "server", "--source", str(DOCS_DIR))
else:
session.run("hugo", "--minify", "--source", str(DOCS_DIR))
@nox.session(default=False)
def tag(session: nox.Session) -> None:
"""Create a signed, annotated tag for a release.
Usage: nox -s tag -- 0.157.0
"""
version = _get_version(session)
tag_name = f"v{version}"
tag_message = f"hugo-python-distributions, version {version}"
result = subprocess.run(
["git", "tag", "-l", tag_name], capture_output=True, text=True, check=False
)
if tag_name in result.stdout:
session.error(f"Tag {tag_name} already exists")
branch = subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"],
capture_output=True,
text=True,
check=True,
).stdout.strip()
if branch != "main":
session.warn(f"You are on branch '{branch}', not 'main'. Proceed with caution.")
session.log(f"Creating signed tag {tag_name}: {tag_message}")
session.run(
"git",
"tag",
"-s",
"-a",
tag_name,
"-m",
tag_message,
external=True,
)
session.log(f"Tag {tag_name} created. Push it with: git push origin {tag_name}")