Formats cells using the Black
uncompromising Python code formatter.
This is quite a hacky solution that relies on the blackcellmagic
extension by csurfer.
It adds the command Format cell with Black
which just
- adds the text
%%black
to the top of the cell, and - runs the cell
You can add a keyboard shortcut by adding something like...
{
"black:format-cell": {
"command": "black:format-cell",
"keys": ["F"],
"selector": ".jp-Notebook:focus"
}
}
... to the keyboard shortcuts in jupyterlab settings.
- JupyterLab
- BlackCellMagic
jupyter labextension install jupyterlab_formatblack
For a development install (requires npm version 4 or later), do the following in the repository directory:
npm install
npm run build
jupyter labextension link .
To rebuild the package and the JupyterLab app:
npm run build
jupyter lab build