Open redeboer opened 2 months ago
Not sure if it's the same issue, or related, but jupyterlab-code-formatter
with ruff
also deletes all content in cells that contain non-standard characters. E.g.
print("°")
gets deleted
Works okay for me. (Same dependencies as in issue description.)
Just to chime in also seeing this issue
Not sure if it's the same issue, or related, but
jupyterlab-code-formatter
withruff
also deletes all content in cells that contain non-standard characters. E.g.print("°")
gets deleted
It seems like the code checks whether the command line formatter wrote to stderr to determine if it cannot handle the input:
But in case of ruff format
this probably does not happen and ruff does not return output to neither standard output nor error. I think it should also check the exit code (https://docs.astral.sh/ruff/formatter/#exit-codes). For backward compatibility with other instances/sub-classes of CommandLineFormatter
maybe checking the exit code should be optional (e.g. toggled by class property) and for now default to False but changed to True in ruff format.
Just to chime in also seeing this issue
Not sure if it's the same issue, or related, but
jupyterlab-code-formatter
withruff
also deletes all content in cells that contain non-standard characters. E.g.print("°")
gets deleted
Same to me. When I used @jbwhit's solution there was the same error, that cells containing non-ascii characters were not formatted. For me adding encoding="utf-8"
in the subprocess.run()
call would fix it.
An exception is required in order to pop up the Jupyterlab Code Formatter Error dialog. Black raises InvalidInput
when black.format_str
fails. My quick and dirty solution is:
RuffFormatFormatter
.raise ValueError(process.stdin)
return code
I think a proper solution would be to subclass CommandLineFormatter
overriding format_code
.
First of all, thanks a ton for fixing support for Ruff since v3.0.0! 🎉
Bug description
It seems that
jupyterlab-code-formatter
withruff
deletes all content in cells that contain syntax errors.Reproduce
Running Jupyter Lab in a
venv
in Python 3.12 with these dependenciesand using these minimal settings
Context