-
Notifications
You must be signed in to change notification settings - Fork 1
/
noxfile.py
148 lines (127 loc) · 3.93 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
# -*- coding: utf-8 -*-
"""Nox session configuration."""
import tempfile
from typing import Any, List
import nox
from nox.sessions import Session
PACKAGE: str = "gtexquery"
LOCATIONS: List[str] = [
PACKAGE,
"noxfile.py",
"tests",
]
VERSIONS: List[str] = [
"3.9",
]
nox.options.stop_on_first_error = False
nox.options.reuse_existing_virtualenvs = True
def constrained_install(session: Session, *args: str, **kwargs: Any) -> None:
"""Install packages with poetry version constraint."""
with tempfile.NamedTemporaryFile() as reqs:
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
f"--output={reqs.name}",
external=True,
)
session.install(f"--constraint={reqs.name}", *args, **kwargs)
@nox.session(python="3.9")
def form(session: Session) -> None:
"""Format code with isort and black."""
args = session.posargs or LOCATIONS
constrained_install(session, "isort", "black")
session.run("isort", *args)
session.run("black", *args)
@nox.session(python=VERSIONS)
def lint(session: Session) -> None:
"""Lint files with flake8."""
args = session.posargs or LOCATIONS
constrained_install(
session,
"flake8",
"pyproject-flake8",
"flake8-annotations",
"flake8-bandit",
"flake8-bugbear",
"flake8-comprehensions",
"flake8-docstrings",
"flake8-pytest-style",
"flake8-spellcheck",
"darglint",
)
session.run("pflake8", *args)
@nox.session(python=VERSIONS)
def type(session: Session) -> None:
"""Type check files with mypy."""
args = session.posargs or LOCATIONS
constrained_install(session, "mypy", "types-requests")
session.run("mypy", "--ignore-missing-imports", *args)
@nox.session(python=VERSIONS)
def security(session: Session) -> None:
"""Check security safety."""
constrained_install(session, "safety")
with tempfile.NamedTemporaryFile() as reqs:
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
f"--output={reqs.name}",
external=True,
)
session.run("safety", "check", f"--file={reqs.name}", "--full-report")
@nox.session(python=VERSIONS)
def tests(session: Session) -> None:
"""Run the test suite with pytest."""
args = session.posargs or []
session.run("poetry", "install", "--no-dev", external=True)
constrained_install( # These are required for tests. Don't clutter w/ all dependencies!
session,
"coverage",
"pytest",
"pytest-clarity",
"pytest-sugar",
"pytest-mock",
"requests-mock",
"pytest-cov",
"typeguard", # Though typing, run best in pytest
"six",
)
session.run("pytest", *args)
@nox.session(python=VERSIONS)
def doc_tests(session: Session) -> None:
"""Test docstrings with xdoctest.
As xdoctest does not seem to detect if multiple sources are passed,
session run must be called over each cource manually.
Parameters
----------
session : Session
nox session
"""
args = session.posargs or ["all"]
command = [
"python",
"-m",
"xdoctest",
"--verbose",
"2",
"--report",
"cdiff",
"--nocolor",
]
session.run("poetry", "install", "--no-dev", external=True)
constrained_install(session, "xdoctest")
for x in LOCATIONS:
session.run(*command, x, *args)
@nox.session(python="3.9")
def doc_build(session: Session) -> None:
"""Build the documentation."""
session.run("poetry", "install", "--no-dev", external=True)
constrained_install(
session, "sphinx", "sphinx-rtd-theme", "myst-parser", "pytest", "requests-mock"
)
session.run("sphinx-build", "docs", "docs/_build")