-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnoxfile.py
74 lines (58 loc) · 1.82 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
import subprocess
from pathlib import Path
import nox
import parver
BASE_PATH = Path(__file__).resolve().parent
PACKAGE_ROOT = BASE_PATH / "src/pip_shims"
INIT_PY = PACKAGE_ROOT / "__init__.py"
PIP_VERSIONS = [
"pip~=20.0.0",
"pip~=20.1.0",
"pip~=20.2.0",
"pip~=20.3.0",
"pip~=21.0.0",
"pip~=21.1.0",
"pip~=21.2.0",
"pip~=21.3.0",
"pip~=22.0.0",
"pip~=22.1.0",
"pip~=22.1.2",
"git+https://github.com/pypa/pip.git",
]
@nox.session
@nox.parametrize("pip", PIP_VERSIONS)
def tests(session: nox.Session, pip: str):
session.install("-e", ".[tests]")
session.install(pip)
session.run("pytest", "-ra", "tests")
@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))
@nox.session
def bump_version(session: nox.Session):
new_version = _prebump(_current_version())
_write_version(new_version)
return new_version