forked from sixty-north/cosmic-ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
65 lines (49 loc) · 1.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
import argparse
import nox
nox.options.sessions = ["tests-3.11"]
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
def tests(session):
session.install(".[test]")
command = ["pytest", "tests"] + list(session.posargs)
session.run(*command)
@nox.session
def lint(session):
session.install(".[dev]")
session.log("Checking syntax with flake8")
check_syntax = "flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics"
session.run(*check_syntax.split())
session.log("Checking style with flake8")
check_style = "flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics"
session.run(*check_style.split())
@nox.session
def release(session: nox.Session) -> None:
"""
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)