-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
201 lines (157 loc) · 4.77 KB
/
noxfile.py
File metadata and controls
201 lines (157 loc) · 4.77 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# -*- coding: utf-8 -*-
from __future__ import annotations
import os
from os import path
from shutil import which
import nox
echo = print
LIBS = (
"aiopen",
"asyncify",
"dgpylibs",
"dgpytest",
"fmts",
"funkify",
"h5",
"jsonbourne",
"lager",
"listless",
"requires",
"shellfish",
"xtyping",
)
def is_win() -> bool:
"""Determine if current operating system is windows
Returns:
True if on a windows machine; False otherwise
"""
return os.name == "nt"
nox.options.envdir = ".nox_win" if is_win() else ".nox"
IS_GITLAB_CI = "GITLAB_CI" in os.environ
IS_GITHUB_CI = "CI" in os.environ and os.environ["CI"] == "true"
REUSE_TEST_ENVS = True
PWD = path.abspath(path.dirname(__file__))
LIBS_DIR = path.join(PWD, "libs")
VENV_BACKEND = None if is_win() or IS_GITHUB_CI or not which("conda") else "conda"
LIB_DIRS = {
el: path.join(LIBS_DIR, el)
for el in os.listdir(LIBS_DIR)
if el[0] != "." and el in LIBS
}
SOURCE_DIRS = {el: path.join(LIBS_DIR, el, "src", el) for el in LIBS}
TESTS_DIRS = {el: path.join(LIBS_DIR, el, "tests") for el in LIB_DIRS}
# #############
# ### UTILS ###
# #############
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def pipc(session: nox.Session) -> None:
session.install("pip-tools")
reqs_ini = (
"dev.in",
"docs.in",
)
for reqs_file in reqs_ini:
output_filepath = path.join(
PWD, "requirements", reqs_file.replace(".in", ".txt")
)
session.run(
"uv",
"pip",
"compile",
"-o",
output_filepath,
path.join(PWD, "requirements", reqs_file),
)
def _mypy(session: nox.Session) -> None:
session.install(
"-U",
"mypy",
"typing-extensions",
"pydantic",
"pydantic_core",
"anyio",
"pytest",
"nox",
)
session.install("orjson", "types-orjson", "fastapi", "click==8.1.3")
session.run("mypy", "--version")
session.run(
"mypy",
"--show-error-codes",
"--config-file",
"./pyproject.toml",
*list(SOURCE_DIRS.values()),
)
for lib in LIBS:
noxfile_path = path.join("libs", lib, "noxfile.py")
args = [
"mypy",
"--show-error-codes",
"--config-file",
"./pyproject.toml",
*list(SOURCE_DIRS.values()),
path.join("libs", lib, "tests"),
]
if path.exists(noxfile_path):
args.append(noxfile_path)
session.run(*args)
def _ruff(session: nox.Session) -> None:
session.install("ruff")
session.run("ruff", "--version")
session.run("ruff", "check", ".")
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def mypy(session: nox.Session) -> None:
_mypy(session)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def lint(session: nox.Session) -> None:
_mypy(session)
ruffext = """
[tool.ruff]
extend = "../../pyproject.toml"
"""
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def dev(session: nox.Session) -> None:
import tomllib
from pprint import pprint
for libname, dirpath in LIB_DIRS.items():
echo(libname, dirpath)
pyproject_toml_fspath = path.join(dirpath, "pyproject.toml")
with open(pyproject_toml_fspath) as f:
pyproject_toml_str = f.read().rstrip("\n")
data = tomllib.loads(pyproject_toml_str)
pprint(data)
def _pkg_entry_point(pkg_name: str) -> str:
return "\n".join([
"# -*- coding: utf-8 -*-",
f'"""pkg entry ~ `python -m {pkg_name}`"""',
"import sys",
"",
f"from {pkg_name}._meta import __pkgroot__, __title__, __version__",
"",
"sys.stdout.write(",
' f"package: {__title__}\\nversion: {__version__}\\npkgroot: {__pkgroot__}\\n"',
")",
"",
])
def _install_mkdocs_deps(session: nox.Session) -> None:
session.install(
"mkdocs", # docs!
"mkdocs-material", # material theme
"mkdocs-jupyter", # rendering jupyter notebooks
"mkdocstrings[python]", # render docstrings 2 markdown
"markdown-callouts", # callouts
"black", # code formatting for mkdocstrings-signatures
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def mkdocs_serve(session: nox.Session) -> None:
_install_mkdocs_deps(session)
session.run("mkdocs", "serve")
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def mkdocs(session: nox.Session) -> None:
_install_mkdocs_deps(session)
session.run("mkdocs", "build")
@nox.session(reuse_venv=True)
def freeze(session: nox.Session) -> None:
for lib in LIBS:
session.install(lib)
_freeze = session.run("pip", "freeze", "--local", "-l")