-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
107 lines (78 loc) · 2.92 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
import nox
import argparse
nox.options.stop_on_first_error = True
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_missing_interpreters = False
# default to the testing sessions
nox.options.sessions = ["black", "lint", "spell_check", "tests", "docs", "wheel"]
locations = "sub3", "tests", "noxfile.py", "setup.py"
@nox.session(python="3.10")
def black(session):
"""Run black code formatter."""
session.install("black")
session.run("black", *locations)
@nox.session(python="3.10")
def lint(session):
session.install("flake8", "black")
session.run("flake8", "--version")
session.run("black", "--version")
session.run("black", "--check", *locations)
session.run("flake8", *locations)
@nox.session(python="3.10")
def spell_check(session):
session.install("-e", ".")
session.install("-r", "docs/requirements.txt")
# Generate documentation into `build/docs`
session.run(
"sphinx-build", "-W", "-b", "spelling", "-v", "docs/", "docs/_build/html"
)
@nox.session(python=["3.10"])
def tests(session):
session.install("-e", ".")
session.install("-r", "tests/requirements.txt")
session.run("pytest")
@nox.session(python="3.10")
def docs(session):
session.install("-e", ".")
session.install("-r", "docs/requirements.txt")
# Generate documentation into `build/docs`
session.run("sphinx-build", "-W", "-b", "html", "-v", "docs/", "docs/_build/html")
@nox.session(python="3.10")
def wheel(session):
session.install("twine", "wheel")
# Generate documentation into `build/docs`
session.run("python", "setup.py", "sdist", "bdist_wheel")
session.run("twine", "check", "dist/*")
@nox.session
def release(session: nox.Session) -> None:
wheel(session)
"""
Kicks off an automated release process by creating and pushing a new tag.
Invokes bump2version with the posarg setting the version.
Usage:
$ nox -s release -- [major|minor|patch]
"""
parser = argparse.ArgumentParser(description="Release a semver version.")
parser.add_argument(
"version",
type=str,
nargs=1,
help="The type of semver release to make.",
choices={"major", "minor", "patch"},
)
args: argparse.Namespace = parser.parse_args(args=session.posargs)
version: str = args.version.pop()
# If we get here, we should be good to go
# Let's do a final check for safety
confirm = input(
f"You are about to bump the {version!r} version. Are you sure? [y/n]: "
)
# Abort on anything other than 'y'
if confirm.lower().strip() != "y":
session.error(f"You said no when prompted to bump the {version!r} version.")
session.install("bump2version")
session.log(f"Bumping the {version!r} version")
session.run("bump2version", version)
session.log("Pushing the new tag")
session.run("git", "push", external=True)
session.run("git", "push", "--tags", external=True)