koxudaxi / ruff-pycharm-plugin

PyCharm plugin for ruff. This plugin provides reformat code using ruff.
MIT License
184 stars 7 forks source link

Ruff not running on Reformat Code command #334

Closed kjy5 closed 3 months ago

kjy5 commented 7 months ago

Describe the bug With the "Run ruff when Reformat Code" option is checked, ruff format is not used over the default PyCharm formatter.

To Reproduce Steps to reproduce the behavior:

  1. Enable "Run ruff when Reformat Code" and ensure a ruff executable is picked (for me it was in my local virtual environment)
  2. Use Ctrl/Command + Alt + L or the "Reformat Code" menu option to trigger a code reformat
  3. Notice that ruff was not used to reformat the code and instead the built-in PyCharm formatter was used

Expected behavior Ruff should have been used to format the code. You can tell the difference by manually running ruff from the CLI.

Screenshots If applicable, add screenshots to help explain your problem. Also, gif movies are recommended.

Environments (please complete the following information):

Additional context Python 12

Warraybe commented 7 months ago

Ruff-issue

I am experiencing the same issue. Here is a gif to show what is occurring.

koxudaxi commented 6 months ago

@kjy5 @Warraybe I'm sorry for my late reply. I have tested it on my local machine. Unfortunately, I can't reproduce the problem. Could you please share your project structure? I want to know the python file and pyproject.toml file places. I guess the PR will fix your issue.

arogozhnikov commented 6 months ago

Hi @koxudaxi , thank you for the tool.

I am not sure if it is the same problem, but here is the crash log (happens on every IDE start):

currently I have ruff==0.1.10 and plugin==0.0.19

Edit: this error seems to be duplicate of https://github.com/koxudaxi/ruff-pycharm-plugin/issues/329#issuecomment-1887068669

ExternalToolPass: 

com.intellij.diagnostic.PluginException: annotator: com.koxudaxi.ruff.RuffExternalAnnotator@4f728d8e (class com.koxudaxi.ruff.RuffExternalAnnotator) [Plugin: com.koxudaxi.ruff]
    at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:23)
    at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:89)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.processError(ExternalToolPass.java:259)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:207)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:198)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.runChangeAware(ExternalToolPass.java:274)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$1(ExternalToolPass.java:176)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:361)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:339)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:175)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:350)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:340)
    at com.intellij.util.ui.update.MergingUpdateQueue.doExecute(MergingUpdateQueue.java:297)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:280)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:245)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:249)
    at com.intellij.util.Alarm$Request.runSafely(Alarm.java:365)
    at com.intellij.util.Alarm$Request.run(Alarm.java:354)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:248)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:28)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:221)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:227)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:210)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: The following command was executed:

/Users/axelr/pll/venv/bin/ruff --exit-zero --no-cache --force-exclude --no-fix --format json --stdin-filename demo_random.py -

The exit code: 2
The error output of the command:

error: unexpected argument '--format' found

  tip: to pass '--format' as a value, use '-- --format'

Usage: ruff check <FILES|--fix|--no-fix|--unsafe-fixes|--no-unsafe-fixes|--show-source|--no-show-source|--show-fixes|--no-show-fixes|--diff|--watch|--fix-only|--no-fix-only|--ignore-noqa|--output-format <OUTPUT_FORMAT>|--output-file <OUTPUT_FILE>|--target-version <TARGET_VERSION>|--preview|--no-preview|--config <CONFIG>|--select <RULE_CODE>|--ignore <RULE_CODE>|--extend-select <RULE_CODE>|--extend-ignore <RULE_CODE>|--per-file-ignores <PER_FILE_IGNORES>|--extend-per-file-ignores <EXTEND_PER_FILE_IGNORES>|--exclude <FILE_PATTERN>|--extend-exclude <FILE_PATTERN>|--fixable <RULE_CODE>|--unfixable <RULE_CODE>|--extend-fixable <RULE_CODE>|--extend-unfixable <RULE_CODE>|--respect-gitignore|--no-respect-gitignore|--force-exclude|--no-force-exclude|--line-length <LINE_LENGTH>|--dummy-variable-rgx <DUMMY_VARIABLE_RGX>|--no-cache|--isolated|--cache-dir <CACHE_DIR>|--stdin-filename <STDIN_FILENAME>|--exit-zero|--exit-non-zero-on-fix|--statistics|--add-noqa|--show-files|--show-settings|--extension <EXTENSION>|--ecosystem-ci>

For more information, try '--help'.

Error Running Ruff
    at com.koxudaxi.ruff.RuffKt.runCommand(Ruff.kt:191)
    at com.koxudaxi.ruff.RuffKt.runCommand(Ruff.kt:137)
    at com.koxudaxi.ruff.RuffKt.runRuff(Ruff.kt:243)
    at com.koxudaxi.ruff.RuffExternalAnnotator.doAnnotate(RuffExternalAnnotator.kt:54)
    at com.koxudaxi.ruff.RuffExternalAnnotator.doAnnotate(RuffExternalAnnotator.kt:22)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:204)
    ... 36 more
Kroppeb commented 5 months ago

Hi I found this: https://github.com/astral-sh/ruff/issues/7990

It seems they renamed the --format argument to --output-format

Kroppeb commented 5 months ago

Using ruff==0.1 seems to avoid crashing the plugin, but it still doesn't work 🤔

koxudaxi commented 5 months ago

@arogozhnikov @Kroppeb Sorry for the late reply. My expectation is that the plugin should detect the ruff version correctly and switch the argument to the appropriate one.

There may be a problem with version detection.

arogozhnikov commented 5 months ago

@koxudaxi I've just tried changing to ruff==0.1.0 and it seems to work (and I don't see any crashes). plugin==0.0.19

Kroppeb commented 5 months ago

Mmh, strange I still don't see ruff working.

hgalytoby commented 5 months ago

Hi all, I've recently started using ruff (0.2.2) and I've also installed the ruff plugins (0.0.27).

I Reformat is not working, but lint is.

20240220_222114

koxudaxi commented 5 months ago

@hgalytoby I can't reproduce your problem. Have you enabled the Use ruff format ... option in the settings? image

koxudaxi commented 5 months ago

@arogozhnikov @Kroppeb

I've just tried changing to ruff==0.1.0 and it seems to work (and I don't see any crashes). plugin==0.0.19

I guess the problem is resolved in the v0.0.29 Could you please try it?

arogozhnikov commented 5 months ago

Could you please try it?

Updated ruff to 0.2.2 and plugin to 0.0.29, and it seems to work for me. Thanks!

hgalytoby commented 5 months ago

@hgalytoby I can't reproduce your problem. Have you enabled the Use ruff format ... option in the settings? image

Thank you, it's working now.

koxudaxi commented 5 months ago

@Kroppeb

Mmh, strange I still don't see ruff working.

If the plugin version 0.0.29 doesn't work with ruff==0.1, please let me know the details of your environment and code.

MartinHammarstedt commented 4 months ago

This still doesn't work for me. I'm using plugin version 0.0.30, ruff version 0.3.2 and PyCharm 2023.3.4 in Ubuntu. My settings are the same as in your screenshot above.

Kroppeb commented 4 months ago

@Kroppeb

Mmh, strange I still don't see ruff working.

If the plugin version 0.0.29 doesn't work with ruff==0.1, please let me know the details of your environment and code.

@koxudaxi, whoops, somehow missed the reply? I have tried enabling the LSP server setting, and got an error once that Intellij couldn't stop the language server because it didn't exist. Not sure if that's related to this. Also not sure what triggered it, I think I had just restarted pycharm after an unrelated error?

I use windows, I can give you the full information tomorrow.

seandearnaley commented 4 months ago

I recently installed ruff at our company, several users have reported that pycharm reformat does not use ruff, we're using ruff 0.3.2, extension version 0.0.31, pycharm 2023.3.5, mac m1 sonoma 14.4.1. same settings as user but tried all of them and it does not work, just uses the pycharm formatter. tried local and remote interpreters, doesn't seem to work at all. I wonder if you've had a regression somewhere?

koxudaxi commented 3 months ago

I hope the problem has been resolved in v0.0.32 If you will meet the problem, then please leave a comment. https://github.com/koxudaxi/ruff-pycharm-plugin/pull/409