Package: jupyter-black
jupyter-blackmaster:dev:A simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code
automatically using Black. Fork ofdnanhkhoa/nb_blackwith a few minor
modifications:FeaturesOnce loaded, automatically format syntactically correctjupytercells withblackonce they are run.Enhancements compared todnanhkhoa/nb_black:Configurability:Try to read black config frompyproject.tomlif availableOverride settings such as line length andblack.TargetVersionif
desiredUsesblack.format_cellto greatly simplify the codebaseAdds testsSlightly more responsive (no longer requiressetTimeoutand a delay)Free software: MITIntroductionblackis an extremely popular python formatter.Jupyteris an
awesome way to run python. This extension helps you automaticallyblacken
yourjupyter.DependenciesPython >= 3.7Seesetup.cfgQuickstartpython3 -m venv .venv && source ./.venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install jupyter-black jupyter
python3 -m jupyter notebookFrom here, there are two ways to load the extension:Configurable (recommended):importjupyter_blackjupyter_black.load()To look at configuration options:jupyter_black.load??For example:importblackimportjupyter_blackjupyter_black.load(lab=False,line_length=79,verbosity="DEBUG",target_version=black.TargetVersion.PY310,)The other way:%load_extjupyter_blackThis will load the extension using your defaults frompyproject.tomlif
available, or use theblackdefaults. Please note that this defaults tolab=True, since moving to lab instead of standalone notebook installations
seems to be the direction of the jupyter project; this means this method of
loading will only work in JupyterLab, not in a standard notebook. For now,
users running a standalone notebook (instead of lab) need to use the
recommended (configurable) loading approach above.Development SetupClone the repo:git clone https://github.com/n8henrie/jupyter-black && cd jupyter-blackMake a virtualenv:python3 -m venv .venvActivate venv, update pip, and install editable test/dev version:$source./.venv/bin/activate$./.venv/bin/python-mpipinstall--upgradepip$./.venv/bin/python-mpipinstall-e.[test,dev]Notes:Tests useplaywrightYou'll need to run this command (once) prior to running the tests:python -m playwright install --with-deps firefoxtoxwill automatically run these installation steps (helpful for CI)If desired, pass the--no-headlessflag topytestfor local debuggingTODOContribution ideas:More tests, currently very basicEnsure config is overridden in unsurprising waysEnsure other config options are properly passed toblackEnsure thatpyproject.tomlis searched for properlyWrite tests for jupyter lab, currently only tested for notebookI think the fixture could easily be modularized to also work forlab,
but haven't done the work yetContributingPlease seeCONTRIBUTING.mdandTODO.Troubleshooting / FAQHow can I install an older / specific version ofjupyter black?Install from a tag:pip install git+git://github.com/n8henrie/jupyter-black.git@v0.1.0Install from a specific commit:pip install git+git://github.com/n8henrie/jupyter-black.git@aabc123def456ghi789AcknowledgementsMany thanks todnanhkhoa/nb_blackfor
the original version!And of course many thanks to theblackandjupyterteams.Also, after establishing the repo and reserving the name on PyPI, I noticed
there is another library of the same name:drillan/jupyter-black. It looks
like there have been no commits in the last 2 years, and it was never put in
PyPI, so I think at this point I'll continue with this name. Sorry if this
causes any trouble or confusion. I'll note that @drillan's library probably
does things therightway by installing as annbextension.Buy Me a Coffee☕️Changelog0.3.4 :: 2023-04-27Only pass toblack.Modeoptions frompyproject.tomlthat are valid forblack.Mode. Thanks @rldotai,https://github.com/n8henrie/jupyter-black/issues/70.3.2, 0.3.3 :: 2022-11-20Remove version constraints (thanks: @JakobGM,https://github.com/n8henrie/jupyter-black/issues/6)Update CI to ensure publishing should work0.3.1 :: 2022-03-08Fix description (thanks: @bryanwweber)Version bump for PyPI0.3.0 :: 2022-03-06Default tolab=TrueAdd warning popup for users that load in notebook withlab=True(including via%load_ext)Fix tests for the aboveMight as well minor version bump since this changes the API, even if
still0.x0.2.1 :: 20220-03-04Python 3.10 supportBlack 22 support0.2.0 :: 2021-11-14Breaking change: default tolab=True;%load_ext jupyter_blackwill now
work in jupyterlab and no longer work in a standalone notebook0.1.1 :: 2021-09-28Unload the proper event0.1.0 :: 2021-09-28First release on PyPI.