forked from gwforg/gwf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
145 lines (113 loc) · 3.33 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
import nox
import os
import shutil
from fnmatch import fnmatch
PURGE_PATTERNS = [
"__pycache__/*",
"docs/_build/*",
".coverage/*",
".egg-info/*",
".egg/*",
".eggs/*",
".gwf/*",
".gwfconf.json",
".pytest_cache",
"./conda-bld",
"dist",
"*.pyc",
]
def matches_pattern(path):
for pattern in PURGE_PATTERNS:
if fnmatch(path, pattern):
return True
return False
@nox.session
def clean(session):
def delete_recursively(path):
if os.path.isdir(path):
for child in os.scandir(path):
delete_recursively(child.path)
print("Deleting directory", path)
os.rmdir(path)
else:
print("Deleting file", path)
os.remove(path)
for root, dirs, files in os.walk(".", topdown=False):
for name in dirs + files:
if matches_pattern(name):
delete_recursively(os.path.join(root, name))
@nox.session
def build(session):
session.install("flit")
session.run("flit", "build", "--no-setup-py", "--format", "wheel")
@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
def test(session):
# urllib3 v2 came out and shows an openssl error (at least on Py37).
# For now we'll just force <2 to make stuff work.
session.install("urllib3<2", "flit")
session.run("flit", "install", "-s", "--deps", "production")
session.install(
"flake8",
"pytest",
"pytest-click",
"pytest-cov",
"pytest-flake8",
"pytest-mock",
"pytest-runner",
"pytest-asyncio",
)
session.run(
"pytest",
"--cov-config",
"pyproject.toml",
"--cov",
"gwf",
"tests/",
env={"COVERAGE_FILE": f".coverage.{session.python}"},
)
if session.interactive:
session.notify("coverage")
@nox.session(python="3.10")
def coverage(session):
session.install("coverage[toml]")
session.run("coverage", "combine")
session.run("coverage", "report", "--fail-under=65", "--show-missing")
session.run("coverage", "erase")
token = os.getenv("COVERALLS_REPO_TOKEN")
if token:
session.install("coveralls")
session.run("coveralls", env={"COVERALLS_REPO_TOKEN": token})
@nox.session
def format(session):
session.install("black", "isort")
files = ["src/gwf", "tests"]
session.run("black", *files)
session.run("isort", *files)
@nox.session
def lint(session):
session.install("black", "isort", "flake8")
files = ["src/gwf", "tests"]
session.run("black", "--check", *files)
session.run("isort", "--check", *files)
# TODO: Also lint tests at some point...
session.run("flake8", "src/gwf")
@nox.session(python="3.10")
def docs(session):
session.install("flit")
session.run("flit", "install", "-s", "--deps", "production")
session.install(
"sphinx",
"sphinx-autobuild",
"furo",
)
session.cd("docs")
if os.path.exists("_build"):
shutil.rmtree("_build")
# TODO: Add -W to treat warnings as errors
sphinx_args = ["-b", "dirhtml", ".", "_build/dirhtml"]
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)