From 15e4636b89899aeb1220c61b3471984105642271 Mon Sep 17 00:00:00 2001 From: williserdman Date: Mon, 1 Aug 2022 23:55:57 +0000 Subject: [PATCH 1/2] created script to clean notebooks using Jeremy's clean tool the script will clean all the notebooks in the root folder, and output them into the `clean` folder. the README has also been updated with instructions on how to run this command. added functionality to create `clean` directory to the clean tool --- basic_clean_notebooks.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 basic_clean_notebooks.py diff --git a/basic_clean_notebooks.py b/basic_clean_notebooks.py new file mode 100644 index 000000000..11f5e58a2 --- /dev/null +++ b/basic_clean_notebooks.py @@ -0,0 +1,2 @@ +import tools.clean +tools.clean.proc_all() \ No newline at end of file From 5efc95b13c0f89f0bb5d3fa5a71eaeb893384e5f Mon Sep 17 00:00:00 2001 From: williserdman Date: Tue, 2 Aug 2022 00:03:43 +0000 Subject: [PATCH 2/2] README updated with new script README now includes instructions for how to create the `clean` folder clean.py now creates a folder called `clean` --- README.md | 1 + tools/clean.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 3999515c0..926b3a94e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This is where you'll find the notebooks, slides, and spreadsheets for the 2022 e - Repo root: notebooks - `clean` folder: notebooks without prose or outputs + - in your CLI run `python3 basic_clean_notebooks.py` to create this folder - `xl`: Excel spreadsheets - `slides`: Jeremy's slide decks - `tools`: Ignore (tools for creating this repo) diff --git a/tools/clean.py b/tools/clean.py index 624f0c694..63e984f31 100755 --- a/tools/clean.py +++ b/tools/clean.py @@ -4,6 +4,8 @@ from nbdev.export import * from nbdev.clean import * from fastcore.all import * +from nbdev.process import read_nb +import os _re_header = re.compile(r'^#+\s+\S+') _re_clean = re.compile(r'^\s*#\s*clean\s*') @@ -28,6 +30,7 @@ def proc_nb(fname, dest): def proc_all( path:str='.', # Path for source NBs dest_path:str='clean'): # Path for dest NBs + os.mkdir(dest_path) path,dest_path = Path(path),Path(dest_path) fns = [f for f in path.iterdir() if f.suffix == '.ipynb' and not f.name.startswith('_')] for fn in fns: proc_nb(fn, dest=dest_path)