Run on code reformat does not work with PyCharm's native black implementation
Describe the bug When enabling the new native black implementation (added in PyCharm 2023.2), enabling ruff to reformat code has no effect.
To Reproduce Steps to reproduce the behavior:
- Go 'Tools/Black' and enable 'on code reformat'.
- Go to 'Tools/Ruff' and enable 'Run ruff when Reformat Code'
- Reformat a file with
Ctrl + Alt + L
Expected behavior The file should be formatted first by Black and then by Ruff. Instead, it is only formatted by Black.
Environments: IDE: PyCharm Professional 2023.2.1 OS: Windows 11 Ruff Version: 0.0.286 Plugin version: 0.0.20
Also tried with the experimental lsp version, but still not success. I went back to the https://plugins.jetbrains.com/plugin/14321-blackconnect extension to enable both
@urob @jankatins Sorry for the late reply. I looked at the PyCharm source code and it seems that the newly introduced Black integration is called using an internal API separate from the black connect plugin. Because of this difference, I am unsure if the new black integration is compatible with the ruff plugin. You may want to throw a question to JetBrains.
New Black Integration: https://github.com/JetBrains/intellij-community/blob/c128fca2aaddc3fff2754b2abdcbafb60c5c0837/python/src/META-INF/python-core-common.xml#L552
black connect https://github.com/lensvol/intellij-blackconnect/blob/5d0e51e0ada2f8c57076835003143a869f9ba278/src/main/resources/META-INF/plugin.xml#L88-L89
I have created the issue on JetBrains' side. https://youtrack.jetbrains.com/issue/PY-63212/postFormatProcessor-is-not-called-after-Black-integration-format-action
@urob perhaps use ruff's black formatting as an alternate?
Also note ruff additionally has built-in isort support.
Many are moving to ruff and away from separate tools for this reason.
@urob perhaps use ruff's black formatting as an alternate? Also note ruff additionally has built-in isort support.
Many are moving to ruff and away from separate tools for this reason.
Fully agree with you. This issue pre-dates the release of ruff format and https://github.com/koxudaxi/ruff-pycharm-plugin/issues/257 (which btw I had opened for the very reasons you point out)
This may be related. I'm seeing the result of the formatting when I save differ from how ruff format . would format the document. As far as I can tell, I've disabled any of the black formatting options in pycharm. Everything in Tools > Actions of Save is unchecked (I don't see Ruff as an option here by the way).
Is there a way to turn on debug logging for the ruff plugin and / or reformat and save actions? Would be happy to help create documentation for troubleshooting steps.
I'm sorry for slow response.
Is there a way to turn on debug logging for the ruff plugin and / or reformat and save actions? Would be happy to help create documentation for troubleshooting steps.
We don't have the way. I will add the debug option to dump logs.
However, as I wrote here, I suspect a bug on the PyCharm side and consider it difficult here. https://youtrack.jetbrains.com/issue/PY-63212/postFormatProcessor-is-not-called-after-Black-integration-format-action
With ruff format becoming stable, this seems obsolete.
@koxudaxi If you want to close it, that'd be fine for me (the original poster of the issue).