Closed michaelaye closed 2 years ago
I see now that a replacement formatter formally shall be supported by the formatters.py file first, however, the claim of blue
is that it works as a drop-in replacement?
Sorry for the late reply, was extremely burnt out and just switched off.
Yes this needs to be formatters.py
to work, I will fix this in the coming days.
For now you can do the following:-
Edit your Jupyter notebook configuration (usually found ~/.jupyter/jupyter_notebook_config.py
or something like that)
from jupyterlab_code_formatter.formatters import BaseFormatter, handle_line_ending_and_magic, SERVER_FORMATTERS
class BlueFormatter(BaseFormatter):
label = "Apply Blue Formatter"
@property
def importable(self) -> bool:
try:
import black
return True
except ImportError:
return False
@staticmethod
def handle_options(**options):
import black
file_mode_change_version = version.parse("19.3b0")
current_black_version = version.parse(black.__version__)
if current_black_version >= file_mode_change_version:
return {"mode": black.FileMode(**options)}
else:
return options
SERVER_FORMATTERS['blue'] = BlueFormatter()
Though obviously you need to replace the import and the invocation of the library within that snippet.
Merged #250 which add support for this, will let you know once I released this, hopefully in the next few days.
Blue should be now supported with version 1.4.11 :tada:
I fear a new bug is causing this to fail once again. I am currently running jupyter code formatter v1.4.11
(and blue 0.9.0
) and upon specifying blue
as a formatter (identically to the O.P.'s second spec) I encounter the following error:
RuntimeError: A mypyc-compiled version of black has already been imported. This prevents blue from operating properly.
It would seem blue
wants to be left to import black
on it's own?
Checklist prior to opening an issue
Describe the bug Replacing
black
withblue
is not possible. I tried both:and
Diagnostic commands Please attach the output of the following commands (please format them properly)
pip freeze
jupyter labextension list
Other labextensions (built into JupyterLab) app dir: /home/maye/miniconda3/envs/py39/share/jupyter/lab jupyterlab-theme-solarized-dark v2.0.1 enabled OK
❯ jupyter serverextension list Config option
kernel_spec_manager_class
not recognized byListServerExtensionsApp
. config dir: /home/maye/miniconda3/envs/py39/etc/jupyter dask_labextension enabledAs you can see, the command
blue
is in the PATH.