This repository was archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
165 lines (126 loc) · 4.18 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import os.path
import jinja2
import matrix
import nox
nox.options.reuse_existing_virtualenvs = True
DEFAULTS = []
VERSIONS = ["3.8"]
nox.options.sessions = DEFAULTS
COVERAGE = "coverage==5.0a8"
BUILD = None
def default(session):
DEFAULTS.append(session.__name__)
return session
def install_from_requirements(session, filename):
session.install("-r", f"requirements/{filename}.txt")
def _build(session):
global BUILD
if BUILD is None:
install_from_requirements(session, "wheel")
session.run("python", "setup.py", "bdist_wheel")
version = session.run("python", "setup.py", "--version", silent=True).strip()
for filename in os.listdir("dist"):
if filename.endswith(".whl") and f"-{version}-" in filename:
BUILD = os.path.join("dist", filename)
break
@default
@nox.session
def clean(session):
install_from_requirements(session, "coverage")
session.run("coverage", "erase")
@default
@nox.session
def check(session):
install_from_requirements(session, "check")
session.run("python", "setup.py", "sdist")
session.run("python", "setup.py", "bdist_wheel")
session.run("twine", "check", "dist/*")
session.run("check-manifest", ".")
session.run("flake8", "src", "tests", "setup.py")
session.run(
"isort",
"--verbose",
"--check-only",
"--diff",
"--recursive",
"src",
"tests",
"setup.py",
)
@default
@nox.session
def mypy(session):
install_from_requirements(session, "mypy")
session.run("mypy", "src/structured_data")
@default
@nox.session
def build(session):
_build(session)
@default
@nox.session(python=VERSIONS)
def nocov(session):
_build(session)
session.install("--upgrade", BUILD)
install_from_requirements(session, "pytest")
session.run("pytest", "-vv")
@default
@nox.session(python=VERSIONS)
def cover(session):
_build(session)
session.install("--upgrade", BUILD)
install_from_requirements(session, "cover")
session.run("coverage", "run", "--append", "-m", "pytest", "-vv")
@default
@nox.session
def report(session):
install_from_requirements(session, "report")
session.run("limit-coverage")
session.run("coverage", "html", "--show-contexts")
session.run("coverage", "report", "--skip-covered", "-m", "--fail-under=100")
@default
@nox.session
def docs(session):
session.install("-r", "docs/requirements.txt")
session.run("sphinx-build", "-E", "-b", "html", "docs", "dist-docs")
session.run("sphinx-build", "-b", "linkcheck", "docs", "dist-docs")
@nox.session
def mutmut_install(session):
install_from_requirements(session, "mutmut_install")
session.install("-e", ".")
@nox.session
def coveralls(session):
install_from_requirements(session, "coveralls")
session.run("coveralls", "[]")
@nox.session
def codecov(session):
install_from_requirements(session, "codecov")
session.run("coverage", "xml", "--ignore-errors")
session.run("codecov", "-f", "coverage.xml")
@nox.session(python=False)
def bootstrap(session):
del session # Unused
jinja = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.join("ci", "templates")),
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
)
nox_environments = {}
for (alias, conf) in matrix.from_file("setup.cfg").items():
python = conf["python_versions"]
deps = conf["dependencies"]
nox_environments[alias] = {
"python": "python" + python if "py" not in python else python,
"deps": deps.split(),
}
if "coverage_flags" in conf:
cover = {"false": False, "true": True}[conf["coverage_flags"].lower()]
nox_environments[alias].update(cover=cover)
if "environment_variables" in conf:
env_vars = conf["environment_variables"]
nox_environments[alias].update(env_vars=env_vars.split())
for name in os.listdir(os.path.join("ci", "templates")):
with open(name, "w") as fh:
fh.write(jinja.get_template(name).render(nox_environments=nox_environments))
print("Wrote {}".format(name))
print("DONE.")