-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathnoxfile.py
139 lines (107 loc) · 4.01 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
"""Nox sessions.
Even though `nox` is part of the full spaczz dev-install, nothing outside of the stdlib
and `nox` itself should be imported in this module. This is because CI won't have any
other dependencies installed at the time of calling `nox`.
"""
from itertools import product
import nox
from nox.sessions import Session
nox.options.sessions = "lint", "mypy", "tests"
PACKAGE = "spaczz"
LOCATIONS = "src", "tests", "./noxfile.py", "docs/conf.py"
PYTHON = "3.11"
PYTHONS = ["3.11", "3.10", "3.9", "3.8", "3.7"]
SPACY_VERSION = "3.7.4"
SPACY_MYPY_VERSIONS = {SPACY_VERSION: PYTHONS, "3.2.6": PYTHONS[1:]}
SPACY_TEST_VERIONS = {SPACY_VERSION: PYTHONS, "3.0.9": PYTHONS[1:]}
RAPIDFUZZ_VERSION = "3.4.0"
RAPIDFUZZ_VERSIONS = {
"3.6.2": PYTHONS[:-1],
# rapidfuzz dropped Python 3.7 support at v3.5, but the spaczz
# locked version is v3.4, which still supports Python 3.7 like spaczz does.
RAPIDFUZZ_VERSION: PYTHONS,
"2.15.1": PYTHONS,
"1.9.1": PYTHONS[1:],
}
# Formatting
@nox.session(python=PYTHON)
def isort(session: Session) -> None:
"""Run isort import formatter."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--no-root", "--only", "isort", external=True)
session.run("isort", *args)
@nox.session(python=PYTHON)
def black(session: Session) -> None:
"""Run black code formatter."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--no-root", "--only", "black", external=True)
session.run("black", *args)
# Linting
@nox.session(python=PYTHONS)
def lint(session: Session) -> None:
"""Lint using flake8."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--no-root", "--only", "lint", external=True)
session.run("flake8", *args)
# Typechecking
@nox.session(python=PYTHONS)
@nox.parametrize("spacy", list(SPACY_MYPY_VERSIONS.keys()))
def mypy(session: Session, spacy: str) -> None:
"""Type-check using mypy."""
if session.python not in SPACY_MYPY_VERSIONS[spacy]:
return None
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--only", "main,mypy", external=True)
session.run("python", "-m", "pip", "install", "--upgrade", f"spacy=={spacy}")
session.run("mypy", *args)
# Testing
@nox.session(python=PYTHONS)
@nox.parametrize(
["spacy", "rapidfuzz"],
list(product(SPACY_TEST_VERIONS.keys(), RAPIDFUZZ_VERSIONS.keys())),
)
def tests(session: Session, spacy: str, rapidfuzz: str) -> None:
"""Run the test suite."""
if (
session.python not in SPACY_TEST_VERIONS[spacy]
or session.python not in RAPIDFUZZ_VERSIONS[rapidfuzz]
):
return None
args = session.posargs or ["-rxs", "--cov"]
session.run("poetry", "install", "--only", "main,test", external=True)
session.run(
"python",
"-m",
"pip",
"install",
"--upgrade",
f"spacy=={spacy}",
f"rapidfuzz=={rapidfuzz}",
)
session.run("python", "-m", "spacy", "download", "en_core_web_md")
session.run("pytest", *args)
# Docs
@nox.session(python=PYTHONS)
def xdoctest(session: Session) -> None:
"""Run examples with xdoctest."""
args = session.posargs or ["all"]
session.run("poetry", "install", "--only", "main,xdoctest", external=True)
session.run("python", "-m", "spacy", "download", "en_core_web_md")
session.run("xdoctest", PACKAGE, *args)
@nox.session(python=PYTHON)
def readme(session: Session) -> None:
"""Run the README notebook and convert it to Markdown."""
session.run("poetry", "install", "--only", "main,readme", external=True)
session.run(
"jupyter",
"nbconvert",
"--to=markdown",
"--execute",
"notebooks/README.ipynb",
)
session.run("mv", "-f", "notebooks/README.md", "README.md", external=True)
@nox.session(python=PYTHON)
def docs(session: Session) -> None:
"""Build the documentation."""
session.run("poetry", "install", "--only", "main,docs", external=True)
session.run("sphinx-build", "docs", "docs/_build")