-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import nbformat | ||
from nbformat.v4 import new_notebook | ||
|
||
def clean_notebook(file_path): | ||
with open(file_path, 'r', encoding='utf-8') as f: | ||
notebook = nbformat.read(f, as_version=4) | ||
|
||
# Clean cells | ||
for cell in notebook.cells: | ||
if 'outputs' in cell: | ||
cell['outputs'] = [] | ||
if 'execution_count' in cell: | ||
cell['execution_count'] = None | ||
if 'metadata' in cell: | ||
cell['metadata'] = {} | ||
|
||
# Clean notebook metadata | ||
if 'metadata' in notebook: | ||
notebook['metadata'] = {} | ||
|
||
with open(file_path, 'w', encoding='utf-8') as f: | ||
nbformat.write(notebook, f) | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
|
||
# Change this to the directory containing your notebooks | ||
notebook_dir = '../../' | ||
|
||
for root, dirs, files in os.walk(notebook_dir): | ||
for file in files: | ||
if file.endswith('.ipynb'): | ||
file_path = os.path.join(root, file) | ||
clean_notebook(file_path) | ||
print(f'Cleaned {file_path}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: 'Lint Notebook' | ||
on: | ||
push: | ||
branches: | ||
- dev/lint | ||
permissions: | ||
contents: write | ||
id-token: write | ||
|
||
jobs: | ||
gather_stats: | ||
name: 'Gather Stats' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
working-directory: .github/workflows | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
cache: 'pip' | ||
|
||
- name: Install requirements.txt | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip3 install nbformat | ||
- name: Generate reports | ||
working-directory: .github/workflows | ||
run: | | ||
python3 lint.py | ||
- name: Commit changes | ||
uses: EndBug/add-and-commit@v9 | ||
with: | ||
author_name: github-action | ||
author_email: [email protected] | ||
message: 'Github Action: Refresh stats' |