-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclear_notebooks.py
executable file
·38 lines (30 loc) · 1.22 KB
/
clear_notebooks.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
#!/usr/bin/env python3
import argparse
import subprocess
from pathlib import Path
from export_code import Language, supported_languages
def clear_notebooks(folderpath: Path):
for f in folderpath.rglob("*.ipynb"):
if not f.is_file():
continue
command = (f"jupyter nbconvert --clear-output "
f"--ClearOutputPreprocessor.remove_metadata_fields='[(\"ExecuteTime\")]' "
f"--inplace '{f.absolute()}'")
subprocess.run(command, shell=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
all_langs = [l.value for l in supported_languages]
parser.add_argument("-l", "--languages",
nargs='*',
choices=all_langs,
default=all_langs,
help="Language of guide to export")
args = parser.parse_args()
languages = [Language[l] for l in args.languages]
print(f'Clearing notebooks for languages: {", ".join([x.value for x in languages])}')
guides_folderpath = Path("guides")
for language in languages:
print(language)
guide_folderpath = guides_folderpath / language.value
clear_notebooks(guide_folderpath)
print()