-
Notifications
You must be signed in to change notification settings - Fork 12
/
noxfile.py
234 lines (214 loc) · 7.22 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import os
import shutil
from pathlib import Path
import nox
from laminci import upload_docs_artifact
from laminci.nox import (
build_docs,
login_testuser1,
login_testuser2,
run,
run_pre_commit,
)
# we'd like to aggregate coverage information across sessions
# and for this the code needs to be located in the same
# directory in every github action runner
# this also allows to break out an installation section
nox.options.default_venv_backend = "none"
IS_PR = os.getenv("GITHUB_EVENT_NAME") != "push"
CI = os.environ.get("CI")
GROUPS = {}
GROUPS["tutorial"] = [
"tutorial.ipynb",
"tutorial2.ipynb",
"transfer.ipynb",
"arrays.ipynb",
"registries.ipynb",
"setup.ipynb",
]
GROUPS["guide"] = [
"track.ipynb",
"curate-df.ipynb",
"curate-any.ipynb",
"curate-subclass.ipynb",
"schemas.ipynb",
]
GROUPS["biology"] = [
"bio-registries.ipynb",
]
@nox.session
def lint(session: nox.Session) -> None:
run_pre_commit(session)
@nox.session
def install(session):
base_deps = [
"./sub/lnschema-core",
"./sub/lamin-cli",
"./sub/lamindb-setup",
"./sub/bionty",
]
top_deps = [
".[aws,bionty,jupyter]",
]
cmds = [
f"uv pip install {'--system' if CI else ''} --no-cache-dir {' '.join(base_deps)}",
] + [
f"uv pip install {'--system' if CI else ''} --no-cache-dir -e {dep}"
for dep in top_deps
]
[run(session, line) for line in cmds]
@nox.session
@nox.parametrize(
"group",
[
"unit-core",
"unit-storage",
"tutorial",
"guide",
"biology",
"faq",
"storage",
"docs",
"cli",
],
)
def install_ci(session, group):
extras = ""
if group == "unit-core":
extras += "bionty,aws,gcp,zarr,fcs,jupyter"
run(session, "uv pip install --system huggingface_hub")
elif group == "unit-storage":
extras += "aws,zarr,bionty"
run(session, "uv pip install --system tiledbsoma>=1.15.0rc3")
elif group == "tutorial":
extras += "aws,jupyter,bionty"
run(session, "uv pip install --system huggingface_hub")
elif group == "guide":
extras += "aws,bionty,zarr,jupyter"
run(session, "uv pip install --system scanpy")
elif group == "biology":
extras += "bionty,fcs,jupyter"
run(session, "uv pip install --system ipywidgets")
elif group == "faq":
extras += "aws,bionty,jupyter"
run(session, "uv pip install --system --no-deps ./sub/findrefs")
elif group == "storage":
extras += "aws,zarr,bionty,jupyter"
run(
session,
"uv pip install --system --no-deps ./sub/wetlab ./sub/findrefs",
)
run(session, "uv pip install --system vitessce")
elif group == "docs":
extras += "bionty,zarr"
run(session, "uv pip install --system mudata")
run(
session,
"uv pip install --system --no-deps ./sub/wetlab ./sub/findrefs ./sub/clinicore ./sub/omop ./sub/cellregistry ./sub/ourprojects",
)
elif group == "cli":
extras += "jupyter,aws,bionty"
run(session, f"uv pip install --system -e .[dev,{extras}]")
# on the release branch, do not use submodules but run with pypi install
# only exception is the docs group which should always use the submodule
# to push docs fixes fast
# installing this after lamindb to be sure that these packages won't be reinstaled
# during lamindb installation
if IS_PR or group == "docs":
cmd = "uv pip install --system --no-deps ./sub/lamindb-setup ./sub/lnschema-core ./sub/lamin-cli"
run(session, cmd)
if "bionty" in extras:
run(
session,
"uv pip install --system --no-deps ./sub/bionty",
)
@nox.session
@nox.parametrize(
"group",
[
"unit-core",
"unit-storage",
"tutorial",
"guide",
"biology",
"faq",
"storage",
"cli",
],
)
def build(session, group):
import lamindb as ln
login_testuser2(session)
login_testuser1(session)
run(session, "lamin settings set private-django-api true")
coverage_args = "--cov=lamindb --cov-config=pyproject.toml --cov-append --cov-report=term-missing"
if group == "unit-core":
run(session, f"pytest {coverage_args} ./tests/core --durations=50")
elif group == "unit-storage":
run(session, f"pytest {coverage_args} ./tests/storage --durations=50")
elif group == "tutorial":
run(session, "lamin logout")
run(
session, f"pytest -s {coverage_args} ./docs/test_notebooks.py::test_{group}"
)
elif group == "guide":
ln.setup.settings.auto_connect = True
run(
session,
f"pytest -s {coverage_args} ./docs/test_notebooks.py::test_{group}",
)
elif group == "biology":
run(
session,
f"pytest -s {coverage_args} ./docs/test_notebooks.py::test_{group}",
)
elif group == "faq":
ln.setup.settings.auto_connect = True
run(session, f"pytest -s {coverage_args} ./docs/faq")
elif group == "storage":
run(session, f"pytest -s {coverage_args} ./docs/storage")
elif group == "cli":
run(session, f"pytest {coverage_args} ./sub/lamin-cli/tests --durations=50")
# move artifacts into right place
if group in {"tutorial", "guide", "biology"}:
target_dir = Path(f"./docs/{group}")
target_dir.mkdir(exist_ok=True)
for filename in GROUPS[group]:
shutil.copy(Path("docs") / filename, target_dir / filename)
@nox.session
def docs(session):
# move artifacts into right place
for group in ["tutorial", "guide", "biology", "faq", "storage"]:
if Path(f"./docs-{group}").exists():
if Path(f"./docs/{group}").exists():
shutil.rmtree(f"./docs/{group}")
Path(f"./docs-{group}").rename(f"./docs/{group}")
# move back to root level
if group in {"tutorial", "guide", "biology"}:
for path in Path(f"./docs/{group}").glob("*"):
path.rename(f"./docs/{path.name}")
run(
session,
"lamin init --storage ./docsbuild --schema bionty,wetlab,clinicore,findrefs,ourprojects,cellregistry,omop",
)
def generate_cli_docs():
os.environ["NO_RICH"] = "1"
from lamin_cli.__main__ import _generate_help
page = "# `lamin`\n\nFor a guide, see: {doc}`/setup`.\n"
helps = _generate_help()
for name, help_dict in helps.items():
names = name.split(" ")
section = ""
if len(names) != 1:
if len(names) == 2:
separator = "#" * len(names) + " " + " ".join(("lamin", *names[1:]))
else:
separator = ""
section = "```\n\n" + separator
help_string = help_dict["help"].replace("Usage: main", "Usage: lamin")
help_docstring = help_dict["docstring"]
page += f"{section}\n\n{help_docstring}\n\n```text\n{help_string}\n\n"
Path("./docs/cli.md").write_text(page)
generate_cli_docs()
build_docs(session, strip_prefix=True, strict=False)
upload_docs_artifact(aws=True)