-
Notifications
You must be signed in to change notification settings - Fork 57
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
Ruff fix 'formatter' no longer works since 0.1.0 #331
Comments
@felix-cw You might be able to shed some light with an issue I'm having 🙏. I'm using this workaround: https://gist.github.com/jbwhit/eecdd1cac2756df85ad165f437445b0b I'm having some issues with the fact that formatting through jyputerlab_code_formatter doesn't format the same way as if running ruff format from the command line... Mildly infuriating to say the least, and makes it really difficult to use in CI. Any ideas why? It should use the same binary and version, it's just one goes through jyputerlab_code_formatter and the other doesn't as far as I can tell. |
I'm afraid not. I know that this extension formats cell by cell, wheras using ruff directly can potentially see the whole notebook file during formatting. Whether or not this makes a difference I don't know. Another idea could be an environment thing? I tend to have jupyter lab and extensions installed in a "global" conda environment as a host and use kernels from per-project environments. I think that this extension uses the ruff in the jupyter lab environment own environment which could lead to mismatches if you have a similar setup. I don't recall having this problem though, maybe because any mismatches got caught by pre-commit before CI. I've never used jupytext so not sure what the impact could be. |
It's probably as you say, that this extension formats cell by cell. The diff I see most often is that ruff likes to remove empty cells, which this extension does not. Thanks for taking the time to respond! |
Closing as fixed by #333 |
This concerns using
ruff check --fix
to fix code (#296) instead of the newruff format
command.Since ruff 0.1.0, the functionality no longer works. This is because since astral-sh/ruff#7838, ruff emits to stderr, which jupyterlab_code_formatter interprets as an error.
A potential fix is to add the
-e
and-q
flags to the ruff call, which sets the exit code to 0 and suppresses stderr respectively.I edited my installation of jupyterlab_code_formatter to the above and it works, but I haven't had a chance to test more systematically.
The text was updated successfully, but these errors were encountered: