-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Support for formatting the python code in jupyter notebooks #298
Comments
This is great.. Thanks! |
Is there something like
that runs black on all code cells in the notebook(s) from the command line and saves them back in-place? I guess it's just ~ 10 lines using the Jupyter API, but I'd still prefer using it over writing it if someone has written that already. |
@cdeil and others interested in being able to format notebooks from the command line: mcflugen/nbblack is a fairly new project that looks to offer that. |
It's pretty easy to configure the code-prettify Nbextension to use Black. Heres the configuration I use and some install instructions. https://gist.github.com/MarvinT/a072aa992e977496974aaf492287b08c |
@cdeil you can do this with nbQA https://github.com/nbQA-dev/nbQA e.g. from the command line: nbqa black notebook.ipynb --nbqa-mutate e.g. as pre-commit hook: repos:
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.13.1
hooks:
- id: nbqa-black
args: [--nbqa-mutate] Disclaimer: I'm the author of nbQA As of 21.8b0, |
It's now builtin, just |
For |
Thank you very much! It wasn't obvious to me at first from the README what this does. It looks like what you implemented is the command line part so that The other workflow of doing the formatting from within the Jupyter IDE isn't built-in yet in I see pre-commit support was also added: Nice! |
Some third-party plugins do exist, but most don't use One that does, which IMO deserves more attention, is @n8henrie 's https://github.com/n8henrie/jupyter-black |
Jupyter notebooks are quite popular and are used a lot (especially in tasks related to data analysis, visualization etc.).
These notebooks are also used as presentations and tutorials.
It would be great if
black
could format the code within the cells of the notebooks.The text was updated successfully, but these errors were encountered: