Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script that will create the clean folder with cleaned notebooks #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions basic_clean_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import tools.clean
tools.clean.proc_all()
3 changes: 3 additions & 0 deletions tools/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*')
Expand All @@ -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)
Expand Down