srstevenson / nb-clean

Clean Jupyter notebooks for version control. Remove metadata, outputs, and execution counts with Git and pre-commit support.
https://pypi.org/project/nb-clean
ISC License
135 stars 18 forks source link

Support batch and wildcard file names #140

Closed yasirroni closed 1 year ago

yasirroni commented 2 years ago

Support this feature:

nb-clean clean --preserve-cell-outputs  notebooks/*

It first will list all .ipynb files in notebooks/, then iteratively clean all the notebooks.

srstevenson commented 2 years ago

This should already work if globs are expanded by your shell, which they typically are by default in shells like bash and zsh. For example:

$ ls -1 notebooks         
dirty-1.ipynb
dirty-2.ipynb
$ nb-clean check notebooks/*
dirty-1.ipynb cell 0: metadata
dirty-1.ipynb cell 0: execution count
dirty-1.ipynb cell 0: outputs
dirty-1.ipynb metadata: language_info.version
dirty-2.ipynb cell 0: metadata
dirty-2.ipynb cell 0: execution count
dirty-2.ipynb cell 0: outputs
dirty-2.ipynb metadata: language_info.version

However, it would be useful to be able to pass a directory name without a glob (e.g. nb-clean clean notebooks) and have nb-clean operate on that recursively: PRs for this would be welcome.

yasirroni commented 2 years ago

I'm using Windows powershell and the above code is not working (nb-clean clean --preserve-cell-outputs notebooks/*).

srstevenson commented 1 year ago

@yasirroni This should be resolved by #148, but I haven't been able to test on Windows with PowerShell. If you have problems in that environment, please open a new issue.