forked from cta-observatory/cta-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
63 lines (51 loc) · 1.85 KB
/
build.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
import papermill as pm
from pathlib import Path
import logging
logger = logging.getLogger()
def print_notebooks_to_build(workflow_stages):
"""
pretty-print the list of notebooks that will be considered
Parameters
----------
workflow_stages: Dict[str, List[Path]]
dictionary of workflow stage name mapped to list of notebooks within it.
"""
print("======== BUILDING: ===========")
for directory, files in workflow_stages.items():
print(directory, ":")
for nb in files:
print(" - ", nb)
def build_notebooks(stage, notebook_paths, build_dir):
"""
Build a list of notebooks
Parameters
----------
stage: str
name of stage (just for identification purposes)
notebook_paths: List[Path]
list of paths to notebooks
build_dir: Path
path to top-level of output directory
"""
logger.info("Building Stage '%s'", stage)
for path in notebook_paths:
output_path = build_dir/path
output_path.parents[0].mkdir(parents=True, exist_ok=True)
logger.debug("Created %s", path.parents[0])
pm.execute_notebook(
str(path),
str(output_path),
#parameters = dict(alpha=0.6, ratio=0.1)
)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
build_dir = Path("BUILD")
build_dir.mkdir(exist_ok=True)
logging.info("Build directory:", build_dir.resolve())
dirs_to_build = ['Preparation', 'Benchmarks', 'Summaries']
workflow_stages = {x: [path for path in Path(f'./{x}').rglob("*.ipynb")
if '.ipynb_checkpoints' not in path.parts]
for x in dirs_to_build}
print_notebooks_to_build(workflow_stages)
for stage, paths in workflow_stages.items():
build_notebooks(stage, paths, build_dir)