-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcopy_files_from_repo.py
More file actions
52 lines (37 loc) · 1.6 KB
/
copy_files_from_repo.py
File metadata and controls
52 lines (37 loc) · 1.6 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
from __future__ import annotations
"""
mkdocs-gen-files generator for static CogStack AI assets.
This script copies configured notebook files from the repository into the
MkDocs build output (relative to `docs_dir`).
Configuration:
`COPY_SPECS` is a list of dicts with:
- `sourceFilePath`: path to the repo file to copy
- `outputFilePath`: path (relative to MkDocs' `docs_dir`) to write into
"""
from pathlib import Path
import mkdocs_gen_files # type: ignore[import-not-found]
REPO_ROOT = Path(__file__).resolve().parents[2]
# Add more entries here to copy additional static files into documentation.
COPY_SPECS = [
{
"sourceFilePath": "helm-charts/cogstack-ce-helm/charts/jupyterhub/examples/medcat-service-tutorial.ipynb",
"outputFilePath": "platform/cogstack-ai/medcat-service-tutorial.ipynb",
},
{
"sourceFilePath": "helm-charts/cogstack-ce-helm/charts/jupyterhub/examples/medcat-opensearch-e2e.ipynb",
"outputFilePath": "cogstack-ce/tutorial/medcat-opensearch-e2e.ipynb",
},
]
def main() -> None:
"""Copy configured files into the MkDocs virtual filesystem."""
for spec in COPY_SPECS:
source_rel = spec["sourceFilePath"]
output_rel = spec["outputFilePath"]
source_path = REPO_ROOT / source_rel
if not source_path.is_file():
raise FileNotFoundError(f"Source file not found: {source_path}")
output_path = Path(output_rel)
# Write bytes so formats like .ipynb are preserved exactly.
with mkdocs_gen_files.open(output_path.as_posix(), "wb") as f:
f.write(source_path.read_bytes())
main()