forked from sarugaku/requirementslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
86 lines (64 loc) · 2.32 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
import subprocess
from pathlib import Path
import nox
import parver
BASE_PATH = Path(__file__).resolve().parent
PACKAGE_ROOT = BASE_PATH / "src/requirementslib"
INIT_PY = PACKAGE_ROOT / "__init__.py"
@nox.session
def tests(session: nox.Session):
session.install("-e", ".[tests]")
session.run("pytest", "-ra", "tests")
@nox.session
def coverage(session: nox.Session):
session.install(".[tests]", "coveralls")
session.run("pytest", "--cov=requirementslib", "-ra", "tests")
session.run("coveralls")
@nox.session
def docs(session: nox.Session):
session.install(".[docs]")
session.run("sphinx-build", "-b", "html", "docs", "docs/build/html")
@nox.session
def package(session: nox.Session):
session.install("build", "twine")
session.run("pyproject-build")
session.run("twine", "check", "dist/*")
def _current_version() -> parver.Version:
cmd = ["git", "describe", "--tags", "--abbrev=0"]
ver = subprocess.check_output(cmd).decode("utf-8").strip()
return parver.Version.parse(ver)
def _prebump(version: parver.Version) -> parver.Version:
next_version = version.bump_release(index=2).bump_dev()
print(f"[bump] {version} -> {next_version}")
return next_version
def _write_version(v):
lines = []
with INIT_PY.open() as f:
for line in f:
if line.startswith("__version__ = "):
line = f"__version__ = {repr(str(v))}\n".replace("'", '"')
lines.append(line)
with INIT_PY.open("w", newline="\n") as f:
f.write("".join(lines))
def _get_changelog() -> str:
cmd = ["towncrier", "--draft"]
changelog = subprocess.check_output(cmd).decode("utf-8")
print(changelog)
return changelog
@nox.session
def bump_version(session: nox.Session):
new_version = _prebump(_current_version())
_write_version(new_version)
return new_version
@nox.session
def release(session: nox.Session):
version = session.posargs[0]
_write_version(parver.Version.parse(version))
changelog = _get_changelog()
session.run("towncrier", "--yes", "--version", version)
git_commit_cmd = ["git", "commit", "-am", f"Release {version}"]
git_tag_cmd = ["git", "tag", "-sa", version, "-m", changelog]
session.run(*git_commit_cmd)
session.run(*git_tag_cmd)
session.run("git", "push")
session.run("git", "push", "--tags")