nb-clean icon indicating copy to clipboard operation
nb-clean copied to clipboard

Add support for clean --recursive

Open bneijt opened this issue 1 year ago • 1 comments

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

bneijt avatar Sep 07 '22 15:09 bneijt

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. 😃

srstevenson avatar Sep 17 '22 20:09 srstevenson

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

bneijt avatar Sep 19 '22 07:09 bneijt

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.

bneijt avatar Sep 19 '22 07:09 bneijt

@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).

srstevenson avatar Sep 22 '22 20:09 srstevenson

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
@@            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 Coverage Δ
src/nb_clean/cli.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

codecov[bot] avatar Sep 22 '22 20:09 codecov[bot]

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 ;-)

bneijt avatar Sep 22 '22 21:09 bneijt

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

yasirroni avatar Sep 22 '22 22:09 yasirroni

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

bneijt avatar Sep 23 '22 13:09 bneijt

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

srstevenson avatar Sep 25 '22 14:09 srstevenson