forked from wntrblm/nox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
115 lines (96 loc) · 3.49 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
# Copyright 2016 Alethea Katherine Flowers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import functools
import os
import nox
ON_APPVEYOR = os.environ.get("APPVEYOR") == "True"
def is_python_version(session, version):
if not version.startswith(session.python):
return False
py_version = session.run("python", "-V", silent=True)
py_version = py_version.partition(" ")[2].strip()
return py_version.startswith(version)
@nox.session(python=["3.5", "3.6", "3.7", "3.8"])
def tests(session):
"""Run test suite with pytest."""
session.create_tmp()
session.install("-r", "requirements-test.txt")
session.install("-e", ".[tox_to_nox]")
tests = session.posargs or ["tests/"]
if is_python_version(session, "3.6.0"):
session.run("pytest", *tests)
return
session.run(
"pytest", "--cov=nox", "--cov-config", ".coveragerc", "--cov-report=", *tests
)
session.notify("cover")
@nox.session(python=["3.5", "3.6", "3.7", "3.8"], venv_backend="conda")
def conda_tests(session):
"""Run test suite with pytest."""
session.create_tmp()
session.conda_install(
"--file", "requirements-conda-test.txt", "--channel", "conda-forge"
)
session.install("contexter", "--no-deps")
session.install("-e", ".", "--no-deps")
tests = session.posargs or ["tests/"]
session.run("pytest", *tests)
@nox.session
def cover(session):
"""Coverage analysis."""
session.install("coverage")
if ON_APPVEYOR:
fail_under = "--fail-under=99"
else:
fail_under = "--fail-under=100"
session.run("coverage", "report", fail_under, "--show-missing")
session.run("coverage", "erase")
@nox.session(python="3.8")
def blacken(session):
"""Run black code formatter."""
session.install("black==19.3b0", "isort==4.3.21")
files = ["nox", "tests", "noxfile.py", "setup.py"]
session.run("black", *files)
session.run("isort", "--recursive", *files)
@nox.session(python="3.8")
def lint(session):
session.install("flake8==3.7.8", "black==19.3b0", "mypy==0.720")
session.run(
"mypy",
"--disallow-untyped-defs",
"--warn-unused-ignores",
"--ignore-missing-imports",
"nox",
)
files = ["nox", "tests", "noxfile.py", "setup.py"]
session.run("black", "--check", *files)
session.run("flake8", "nox", *files)
@nox.session(python="3.8")
def docs(session):
"""Build the documentation."""
output_dir = os.path.join(session.create_tmp(), "output")
doctrees, html = map(
functools.partial(os.path.join, output_dir), ["doctrees", "html"]
)
session.run("rm", "-rf", output_dir, external=True)
session.install("-r", "requirements-test.txt")
session.install(".")
session.cd("docs")
sphinx_args = ["-b", "html", "-W", "-d", doctrees, ".", html]
if not session.interactive:
sphinx_cmd = "sphinx-build"
else:
sphinx_cmd = "sphinx-autobuild"
sphinx_args.insert(0, "--open-browser")
session.run(sphinx_cmd, *sphinx_args)