-
Notifications
You must be signed in to change notification settings - Fork 3
/
noxfile.py
88 lines (63 loc) · 2.62 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
from pathlib import Path
import nox
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["fix_quality", "quality", "test", "check_version"]
PROJECT_FOLDER = "src"
@nox.session(python=False)
def fix_quality(session):
"""Fixes possible quality errors."""
session.run("poetry", "install", "--sync", external=True)
session.run("black", PROJECT_FOLDER)
session.run("black", "tests")
session.run("black", "docs")
session.run("black", "examples")
session.run("ruff", PROJECT_FOLDER, "--fix")
session.run("ruff", "tests", "--fix")
session.run("ruff", "docs", "--fix")
session.run("ruff", "examples", "--fix")
@nox.session
def quality(session):
session.run("poetry", "install", "--sync", external=True)
session.run("black", PROJECT_FOLDER, "--check")
session.run("black", "tests", "--check")
session.run("mypy", PROJECT_FOLDER)
session.run("ruff", PROJECT_FOLDER)
@nox.session(python=["3.10", "3.11", "3.12"])
def test(session: nox.Session):
session.run("poetry", "install", "--sync", external=True)
if session.python == "3.11":
session.run("coverage", "run", "--source", "src/clipstick", "-m", "pytest")
session.run("coverage", "json")
else:
session.run("pytest", "tests")
@nox.session
def build(session):
session.run("poetry", "build", external=True)
@nox.session
def build_docs(session):
session.run("poetry", "install", "--sync", external=True)
session.run("python", "tools/cogger.py")
session.run("sphinx-build", "docs", "_build")
@nox.session(python=False)
def check_version(session: nox.Session):
"""check whether the version in this branch is newer than the latest tagged version."""
session.run("pip", "install", "packaging")
from packaging.version import Version
branch_version = Version(
session.run("poetry", "version", "--short", external=True, silent=True)
)
# get the released version by checking tags.
released_version = session.run(
"git", "tag", "--list", "--sort=taggerdate", "v*", external=True, silent=True
)
latest = Version(released_version.strip().split("\n")[-1])
print("actual version", branch_version)
print("tagged version", latest)
if branch_version <= latest:
session.error("version not latest")
# check whether this new version string exists inside the CHANGELOG.md
change_log = Path("CHANGELOG.md").read_text(encoding="utf-8")
if f"[{branch_version}]" not in change_log:
session.error(f"missing an entry in the CHANGELOG for version {branch_version}")
else:
print("version is present in changelog.")