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

Add support for recursive check/clean #148

Closed bneijt closed 1 year ago

bneijt commented 2 years ago

This is a draft implementation of --recursive to show the idea in code and get feedback from the author on willingness to merge a feature like this.

If this is something that the project would merge, a finalizing todo may include: [ ] Adding unit tests [ ] Add option to check command as well

srstevenson commented 1 year ago

Hi @bneijt -- this is certainly something I'm willing to merge, if you'd like to add the option to the check command and some tests. 😃

bneijt commented 1 year ago

Added unit test and clean support as well, references https://github.com/srstevenson/nb-clean/issues/147

bneijt commented 1 year ago

Please enable the workflow.

One thing to consider is that the current implementation does not enforce a unique set. If you call nb-clean check -r a a you will get duplicate files, but this will be the same as getting duplicate files by just calling nb-clean check a/a.ipynb a/a.ipynb so I don't think the code should deal with that in a special way.

srstevenson commented 1 year ago

@bneijt How about always expanding the arguments that are passed, and removing the --recursive flag? This would be consistent with what most Python linters/formatters do (all of mypy, Black, isort, flake8, and pylint recurse into directories by default).

codecov[bot] commented 1 year ago

Codecov Report

Base: 97.95% // Head: 98.07% // Increases project coverage by +0.11% :tada:

Coverage data is based on head (6d1574e) compared to base (0019065). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #148 +/- ## ========================================== + Coverage 97.95% 98.07% +0.11% ========================================== Files 3 3 Lines 147 156 +9 ========================================== + Hits 144 153 +9 Misses 3 3 ``` | [Impacted Files](https://codecov.io/gh/srstevenson/nb-clean/pull/148?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Scott+Stevenson) | Coverage Δ | | |---|---|---| | [src/nb\_clean/cli.py](https://codecov.io/gh/srstevenson/nb-clean/pull/148/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Scott+Stevenson#diff-c3JjL25iX2NsZWFuL2NsaS5weQ==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Scott+Stevenson). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Scott+Stevenson)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

bneijt commented 1 year ago

Sounds good to me, I can write that up tomorrow. One thing that you do need to take into account is that clean is a potentiality destructive action that you might not want to recurse automatically. But for check it makes sense.

As you are the maintainer, I leave the choice to you. I'm fine with it, most of my notebook output needs cleaning anyway ;-)

yasirroni commented 1 year ago

I hope that this PR supports what I hope exist in this repo, giving a folder and run nb-clean on all notebooks in the directory, see ny failed attempts in https://github.com/srstevenson/nb-clean/pull/150

bneijt commented 1 year ago

The last commit makes the recursive action default behavior for both clean and check.

srstevenson commented 1 year ago

This is now available in nb-clean 2.3.0 on PyPI.