Skip to content

Commit

Permalink
added ability to not clean cells with tags of quiz or noclean. Keep k…
Browse files Browse the repository at this point in the history
…ernelspec and language_info metadata for notebook
  • Loading branch information
JohnTurnerNIH committed Feb 5, 2025
1 parent 35357e1 commit eb04ab0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def clean_notebook(file_path):

# Clean cells
for cell in notebook.cells:
#skip cells with a quiz or no clean tag
if 'metadata' in cell and 'tags' in cell['metadata'] and ('quiz' in cell['metadata']['tags'] or 'noclean' in cell['metadata']['tags']):
continue
if 'outputs' in cell:
cell['outputs'] = []
if 'execution_count' in cell:
Expand All @@ -18,7 +21,12 @@ def clean_notebook(file_path):

# Clean notebook metadata
if 'metadata' in notebook:
notebook['metadata'] = {}
new_metadata = {}
if 'language_info' in notebook['metadata']:
new_metadata['language_info'] = notebook['metadata']['language_info']
if 'kernelspec' in notebook['metadata']:
new_metadata['kernelspec'] = notebook['metadata']['kernelspec']
notebook['metadata'] = new_metadata

with open(file_path, 'w', encoding='utf-8') as f:
nbformat.write(notebook, f)
Expand Down

0 comments on commit eb04ab0

Please sign in to comment.