-
Notifications
You must be signed in to change notification settings - Fork 442
/
Copy pathnoxfile.py
146 lines (117 loc) · 3.97 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import subprocess
import sys
from pathlib import Path
import nox # type: ignore
python = ["3.6", "3.7", "3.8", "3.9"]
if sys.platform == "win32":
# docs fail on Windows, even if `chcp.com 65001` is used
nox.options.sessions = ["tests", "lint"]
else:
nox.options.sessions = ["tests", "lint", "docs"]
nox.options.reuse_existing_virtualenvs = True
doc_dependencies = [".", "jinja2", "mkdocs", "mkdocs-material"]
lint_dependencies = [
"black==19.10b0",
"flake8",
"flake8-bugbear",
"mypy",
"check-manifest",
"packaging>=20.0",
]
# Packages that need an intact system PATH to compile
# pytest setup clears PATH. So pre-build some wheels to the pip cache.
prebuild_packages = {"all": ["typed-ast", "pyzmq"], "darwin": ["argon2-cffi", "regex"]}
def prebuild_wheels(session, package_dict):
session.install("wheel")
wheel_dir = Path(session.virtualenv.location) / "prebuild_wheels"
wheel_dir.mkdir(exist_ok=True)
for platform in package_dict:
if platform == "all" or platform == sys.platform:
for prebuild_package in package_dict[platform]:
session.run(
"pip",
"wheel",
f"--wheel-dir={wheel_dir}",
prebuild_package,
silent=True,
)
@nox.session(python=python)
def tests(session):
prebuild_wheels(session, prebuild_packages)
session.install("-e", ".", "pytest", "pytest-cov")
tests = session.posargs or ["tests"]
session.run("pytest", "--cov=pipx", "--cov-report=", *tests)
session.notify("cover")
@nox.session
def cover(session):
"""Coverage analysis"""
session.install("coverage")
session.run("coverage", "report", "--show-missing", "--fail-under=70")
session.run("coverage", "erase")
@nox.session(python="3.8")
def lint(session):
session.install(*lint_dependencies)
files = [str(Path("src") / "pipx"), "tests"] + [
str(p) for p in Path(".").glob("*.py")
]
session.run("black", "--check", *files)
session.run("flake8", *files)
session.run("mypy", *files)
session.run("check-manifest")
session.run("python", "setup.py", "check", "--metadata", "--strict")
@nox.session(python="3.8")
def docs(session):
session.install(*doc_dependencies)
session.run("python", "generate_docs.py")
session.run("mkdocs", "build")
@nox.session(python=python)
def develop(session):
session.install(*doc_dependencies, *lint_dependencies)
session.install("-e", ".")
@nox.session(python="3.8")
def build(session):
session.install("setuptools")
session.install("wheel")
session.install("twine")
session.run("rm", "-rf", "dist", "build", external=True)
session.run("python", "setup.py", "--quiet", "sdist", "bdist_wheel")
def has_changes():
status = (
subprocess.run(
"git status --porcelain", shell=True, check=True, stdout=subprocess.PIPE
)
.stdout.decode()
.strip()
)
return len(status) > 0
def get_branch():
return (
subprocess.run(
"git rev-parse --abbrev-ref HEAD",
shell=True,
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.strip()
)
@nox.session(python="3.8")
def publish(session):
if has_changes():
session.error("All changes must be committed or removed before publishing")
branch = get_branch()
if branch != "master":
session.error(f"Must be on 'master' branch. Currently on {branch!r} branch")
build(session)
print("REMINDER: Has the changelog been updated?")
session.run("python", "-m", "twine", "upload", "dist/*")
publish_docs(session)
@nox.session(python="3.8")
def watch_docs(session):
session.install(*doc_dependencies)
session.run("mkdocs", "serve")
@nox.session(python="3.8")
def publish_docs(session):
session.install(*doc_dependencies)
session.run("python", "generate_docs.py")
session.run("mkdocs", "gh-deploy")