-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
266 lines (214 loc) · 6.8 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import os
import shutil
import subprocess
from pathlib import Path
import nox
from dirsync import sync
from laminci import run_notebooks
from laminci.nox import run, run_pre_commit
IS_PR = os.getenv("GITHUB_EVENT_NAME") != "push"
@nox.session
def lint(session: nox.Session) -> None:
run_pre_commit(session)
# for FAQ
INTRODUCITION = """
```{toctree}
:hidden:
:caption: Overview
introduction
tutorial
tutorial2
```
"""
FAQ_MATCH = """\
```
"""
FAQ_APPEND = """\
faq/storage
```
"""
# for Guide
USECASES = """
```{toctree}
:maxdepth: 1
:hidden:
:caption: Use cases
atlases
../by-datatype
../by-registry
../data-flow
pipelines
mlops
visualization
```
"""
# for other topics
OTHER_TOPICS_ORIG = """
```{toctree}
:hidden:
:caption: Other topics
faq
storage
"""
OTHER_TOPICS = """
```{toctree}
:maxdepth: 1
:hidden:
:caption: Key topics
access
security
faq
influences
glossary
"""
# below is needed if we have TOCs in notebooks
# def jsonify(text: str):
# new_lines = []
# # skip last line
# for line in text.split("\n")[:-1]:
# line = rf' "{line}\n",'
# new_lines.append(line)
# return "\n".join(new_lines)
# USECASES = jsonify(USECASES_TEXT)
# OTHER_TOPICS_ORIG = jsonify(OTHER_TOPICS_ORIG_TEXT)
# OTHER_TOPICS = jsonify(OTHER_TOPICS_TEXT)
def replace_content(filename: Path, mapped_content: dict[str, str]) -> None:
with open(filename) as f:
content = f.read()
with open(filename, "w") as f:
for key, value in mapped_content.items():
content = content.replace(key, value)
f.write(content)
def add_line_after(content: str, after: str, new_line: str) -> str:
lines = content.splitlines()
for line_idx, line in enumerate(lines):
if after in line:
lines.insert(line_idx + 1, new_line)
break
return "\n".join(lines)
def pull_from_s3_and_unpack(zip_filename) -> None:
subprocess.run( # noqa S602
f"aws s3 cp s3://lamin-site-assets/docs/{zip_filename} {zip_filename}",
shell=True,
)
shutil.unpack_archive(zip_filename, zip_filename.replace(".zip", ""))
def sync_path(path, target_path):
if target_path.exists():
if target_path.is_dir():
shutil.rmtree(target_path)
else:
target_path.unlink()
path.rename(target_path)
@nox.session
def pull_artifacts(session):
# lamindb
pull_from_s3_and_unpack("lamindb.zip")
Path("lamindb/README.md").rename("README.md")
Path("lamindb/conf.py").unlink()
Path("lamindb/changelog.md").unlink()
Path("lamindb/rest.md").unlink()
for path in Path("lamindb").glob("*"):
if (
path.name == "index.md"
or path.name in {"storage", "storage.md"} # not user facing
or path.name == "faq" # directory treated below
):
continue
print("syncing", path)
if path.is_dir():
sync(path, Path("docs") / path.name, "sync", create=True, ctime=True)
else:
sync_path(path, Path("docs") / path.name)
# lamindb faq
for path in Path("lamindb/faq").glob("*"):
sync_path(path, Path("docs/faq") / path.name)
replace_content("docs/faq.md", {FAQ_MATCH: FAQ_APPEND})
# pipelines
pull_from_s3_and_unpack("redun_lamin_fasta_docs.zip")
Path("redun_lamin_fasta_docs/redun.ipynb").rename("docs/redun.ipynb")
pull_from_s3_and_unpack("nextflow-lamin.zip")
Path("nextflow-lamin/nf_core_scrnaseq.ipynb").rename("docs/nextflow.ipynb")
Path("nextflow-lamin/register_scrnaseq_run.py").rename(
"docs/register_scrnaseq_run.py"
)
pull_from_s3_and_unpack("snakemake_lamin_usecases_docs.zip")
Path("snakemake_lamin_usecases_docs/bulk_rna_seq.ipynb").rename(
"docs/snakemake.ipynb"
)
# mlops
pull_from_s3_and_unpack("lamin-mlops.zip")
Path("lamin-mlops/wandb.ipynb").rename("docs/wandb.ipynb")
Path("lamin-mlops/mnist.ipynb").rename("docs/mnist.ipynb")
# cellxgene-lamin
pull_from_s3_and_unpack("cellxgene-lamin.zip")
for path in Path("cellxgene-lamin/").glob("*"):
if path.name.endswith(("cellxgene.ipynb", "cellxgene-curate.ipynb")):
sync_path(path, Path("docs") / path.name)
# lamin-spatial
pull_from_s3_and_unpack("lamin-spatial.zip")
for path in Path("lamin-spatial/").glob("*"):
if path.name == "rxrx.ipynb":
sync_path(path, Path("docs") / path.name)
elif path.name == "vitessce.ipynb":
sync_path(path, Path("docs") / path.name)
# use-cases
pull_from_s3_and_unpack("lamin-usecases.zip")
for path in Path("lamin-usecases/").glob("*"):
if (
path.name == "index.md"
or path.name == "usecases.md"
or path.name == "changelog.md"
or path.name == "conf.py"
):
continue
print("syncing", path)
sync_path(path, Path("docs") / path.name)
# wetlab (must be after use-cases)
pull_from_s3_and_unpack("wetlab.zip")
sync_path(
Path("wetlab/guide/pert-curator.ipynb"),
Path("docs/perturbation.ipynb"),
)
# amend toctree
with open("docs/guide.md") as f:
content = f.read()
with open("docs/guide.md", "w") as f:
content = content.replace("# Guide", "# Guide" + INTRODUCITION)
content = content.replace(OTHER_TOPICS_ORIG, USECASES + OTHER_TOPICS)
content = add_line_after(content, "curate", "public-ontologies")
f.write(content)
assert Path("docs/includes/features-lamindb.md").exists() # noqa S101
@nox.session
def install(session):
run(
session,
"pip install --no-deps git+https://github.com/laminlabs/lnschema-core git+https://github.com/laminlabs/bionty git+https://github.com/laminlabs/lamindb-setup git+https://github.com/laminlabs/wetlab git+https://github.com/laminlabs/clinicore git+https://github.com/laminlabs/cellregistry git+https://github.com/laminlabs/ourprojects",
)
run(
session,
"pip install"
" lamindb[bionty,jupyter,aws]@git+https://github.com/laminlabs/lamindb@main",
)
run(session, "pip install spatialdata") # temporarily
run(session, "lamin settings set private-django-api true")
@nox.session
def run_nbs(session):
run_notebooks("docs/introduction.ipynb")
run_notebooks("docs/tutorial.ipynb")
run_notebooks("docs/tutorial2.ipynb")
@nox.session
def init(session):
run(
session,
"lamin init --storage ./docsbuild --schema bionty,wetlab,clinicore,cellregistry,ourprojects",
)
@nox.session
def docs(session):
process = subprocess.run( # noqa S602
"lndocs --strict --strip-prefix --error-on-index", shell=True
)
if process.returncode != 0:
# rerun without strict option so see all warnings
run(session, "lndocs --strip-prefix --error-on-index")
# exit with error
exit(1)