Closed mwermelinger closed 1 year ago
hey, thanks for the question
there used to be this argument --nbqa-mutate
, but I removed it as I thought it would make for a simpler user experience if they just run their tools the way they're used to
Do you have a use-case where that would help?
One less CLI argument to think of certainly improves the user experience. Since nbqa is aware of the tools it can be used with, an alternative is to internally have a list of those tools that potentially change code (black, isort, etc.) and so the user would only need to provide the CLI argument when using a new tool that modifies the code.
The efficiency gains would only be noticeable when processing large folders with many notebooks and many magics, and even then it would probably not make much difference. For example, the linter we're working on that checks if code is using Python constructs that weren't taught to students, processes a folder with 1075 notebooks and 13 Python files in 1.5 seconds on my machine. With nbqa (which only processes the notebooks, but more robustly than directly using our tool) it takes 7 seconds.
So, there's really no pressing use case. Feel free to label this issue with ideas, wontfix and close it :-)
thanks for the suggestion - will close then, but please do feel free to get in touch if you have other suggestions / questions
Marco kindly commented in our project why nbqa replaces magics with
hash(hexcode)
so that it can transform back the code. From a quick look at nbqa's code, it seems thatmutate()
always tries to edit the original notebook with the (possibly modified) temporary Python file, then checks if the notebook was actually changed and in that case overwrites the original one. Wouldn't it be simpler and more efficient to tell nbqa in advance (e.g. via a CLI argument--edit
) whether the tool modifies the code? The default would be that it doesn't, since most tools are linters, not formatters.The
project.toml
file could list the tools that modify the input code, e.g.:Apologies if the suggestion is daft, too complicated or unworkable.