Completed
Push — master ( 966df6...24a7f2 )
by Max
23s queued 11s
created

noxfile   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 124
dl 0
loc 166
rs 10
c 0
b 0
f 0
wmc 25

15 Functions

Rating   Name   Duplication   Size   Complexity  
A clean() 0 5 1
A mypy() 0 5 1
A default() 0 3 1
A cover() 0 7 1
A _build() 0 10 5
A codecov() 0 5 1
A docs() 0 6 1
A report() 0 7 1
A install_from_requirements() 0 2 1
A check() 0 18 1
A mutmut_install() 0 4 1
A build() 0 4 1
B bootstrap() 0 31 7
A nocov() 0 7 1
A coveralls() 0 4 1
1
import os.path
2
3
import jinja2
4
import matrix
5
import nox
6
7
nox.options.reuse_existing_virtualenvs = True
8
9
DEFAULTS = []
10
VERSIONS = ["3.7", "3.8"]
11
12
nox.options.sessions = DEFAULTS
13
14
15
COVERAGE = "coverage==5.0a8"
16
BUILD = None
17
18
19
def default(session):
20
    DEFAULTS.append(session.__name__)
21
    return session
22
23
24
def install_from_requirements(session, filename):
25
    session.install("-r", f"requirements/{filename}.txt")
26
27
28
def _build(session):
29
    global BUILD
30
    if BUILD is None:
31
        install_from_requirements(session, "wheel")
32
        session.run("python", "setup.py", "bdist_wheel")
33
        version = session.run("python", "setup.py", "--version", silent=True).strip()
34
        for filename in os.listdir("dist"):
35
            if filename.endswith(".whl") and f"-{version}-" in filename:
36
                BUILD = os.path.join("dist", filename)
37
                break
38
39
40
@default
41
@nox.session
42
def clean(session):
43
    install_from_requirements(session, "coverage")
44
    session.run("coverage", "erase")
45
46
47
@default
48
@nox.session
49
def check(session):
50
    install_from_requirements(session, "check")
51
    session.run("python", "setup.py", "sdist")
52
    session.run("python", "setup.py", "bdist_wheel")
53
    session.run("twine", "check", "dist/*")
54
    session.run("check-manifest", ".")
55
    session.run("flake8", "src", "tests", "setup.py")
56
    session.run(
57
        "isort",
58
        "--verbose",
59
        "--check-only",
60
        "--diff",
61
        "--recursive",
62
        "src",
63
        "tests",
64
        "setup.py",
65
    )
66
67
68
@default
69
@nox.session
70
def mypy(session):
71
    install_from_requirements(session, "mypy")
72
    session.run("mypy", "src/structured_data")
73
74
75
@default
76
@nox.session
77
def build(session):
78
    _build(session)
79
80
81
@default
82
@nox.session(python=VERSIONS)
83
def nocov(session):
84
    _build(session)
85
    session.install("--upgrade", BUILD)
86
    install_from_requirements(session, "pytest")
87
    session.run("pytest", "-vv")
88
89
90
@default
91
@nox.session(python=VERSIONS)
92
def cover(session):
93
    _build(session)
94
    session.install("--upgrade", BUILD)
95
    install_from_requirements(session, "cover")
96
    session.run("coverage", "run", "--append", "-m", "pytest", "-vv")
97
98
99
@default
100
@nox.session
101
def report(session):
102
    install_from_requirements(session, "report")
103
    session.run("limit-coverage")
104
    session.run("coverage", "html", "--show-contexts")
105
    session.run("coverage", "report", "--skip-covered", "-m", "--fail-under=100")
106
107
108
@default
109
@nox.session
110
def docs(session):
111
    session.install("-r", "docs/requirements.txt")
112
    session.run("sphinx-build", "-E", "-b", "html", "docs", "dist-docs")
113
    session.run("sphinx-build", "-b", "linkcheck", "docs", "dist-docs")
114
115
116
@nox.session
117
def mutmut_install(session):
118
    install_from_requirements(session, "mutmut_install")
119
    session.install("-e", ".")
120
121
122
@nox.session
123
def coveralls(session):
124
    install_from_requirements(session, "coveralls")
125
    session.run("coveralls", "[]")
126
127
128
@nox.session
129
def codecov(session):
130
    install_from_requirements(session, "codecov")
131
    session.run("coverage", "xml", "--ignore-errors")
132
    session.run("codecov", "-f", "coverage.xml")
133
134
135
@nox.session(python=False)
136
def bootstrap(session):
137
    del session  # Unused
138
    jinja = jinja2.Environment(
139
        loader=jinja2.FileSystemLoader(os.path.join("ci", "templates")),
140
        trim_blocks=True,
141
        lstrip_blocks=True,
142
        keep_trailing_newline=True,
143
    )
144
145
    nox_environments = {}
146
147
    for (alias, conf) in matrix.from_file("setup.cfg").items():
148
        python = conf["python_versions"]
149
        deps = conf["dependencies"]
150
        nox_environments[alias] = {
151
            "python": "python" + python if "py" not in python else python,
152
            "deps": deps.split(),
153
        }
154
        if "coverage_flags" in conf:
155
            cover = {"false": False, "true": True}[conf["coverage_flags"].lower()]
156
            nox_environments[alias].update(cover=cover)
157
        if "environment_variables" in conf:
158
            env_vars = conf["environment_variables"]
159
            nox_environments[alias].update(env_vars=env_vars.split())
160
161
    for name in os.listdir(os.path.join("ci", "templates")):
162
        with open(name, "w") as fh:
163
            fh.write(jinja.get_template(name).render(nox_environments=nox_environments))
164
        print("Wrote {}".format(name))
165
    print("DONE.")
166