koxudaxi / ruff-pycharm-plugin

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

Config file is ignored when run ruff from the plugin #291

Open koxudaxi opened 11 months ago

koxudaxi commented 11 months ago

Describe the bug Several users have pointed out a problem with config information in pyproject.toml and ruff.toml not being read. However, the config information is applied when the ruff command is invoked directly from the terminal.

I could not reproduce the problem in my environment, so I have created this issue to sort out and resolve the issue.

To Reproduce Steps to reproduce the behavior:

  1. Add configs as pyproject.toml or ruff.toml in a project.
  2. Write code that violates the rules.
  3. See wrong warning

Expected behavior The plugin doesn't show wrong waring (respect configs)

Screenshots I can't reproduce the problem

Environments (please complete the following information):

Related Issues https://github.com/koxudaxi/ruff-pycharm-plugin/issues/277 https://plugins.jetbrains.com/plugin/20574-ruff/reviews#review=91176-91183 https://plugins.jetbrains.com/plugin/20574-ruff/reviews#review=90927-91184

ghost commented 11 months ago

Hi @koxudaxi ,

could you please try with my exact same ruff config in pyproject.toml?

[tool.ruff]
line-length = 120
target-version = "py37"
select = ["A", "B", "C4", "D", "E", "EXE", "F", "FBT", "G", "I", "ICN", "ISC", "N", "PIE", "PL", "Q003", "PT", "Q", "RSE", "RUF", "S", "SIM", "T10", "T20", "TID", "UP", "W", "YTT"]
ignore = ["D100", "D101", "D102", "D103", "D104", "D105", "D106","D107",  "G003", "G004", "PLR0913", "PLR2004", "S113", "SIM108"]
format = "grouped"

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.flake8-quotes]
inline-quotes = "double"
docstring-quotes = "double"
multiline-quotes = "double"

Apart from the ignored files section I've copied the complete ruff config from one of the projects affected by this.

ghost commented 11 months ago

Just added an error in the code and noticed that the ruff plugin is working on this project now. I'll post again if I notice anything.

koxudaxi commented 11 months ago

@xyxz-web Thank you for sharing the example. I have tried the config. But, It works fine in my local.

Could you please share the plugin version, ruff version, and ruff config?

my environment are IDE: PyCharm 2023.2.1 (Professional Edition) OS: macOS 14 Ruff Version 0.1.1 Plugin version 0.0.24

ghost commented 11 months ago

Hi @koxudaxi ,

as mentioned in my second comment it is actually working now. The only change between when it did not work was that I did upgrade several dependencies and restart PyCharm after activating the ruff-lsp option.

Best regards

koxudaxi commented 11 months ago

I did upgrade several dependencies

After the dependencies are installed, and PyCharm has re-detected the package, the plugin will re-set the path to the ruff.

restart PyCharm after activating the ruff-lsp option.

ruff-lsp is not enabled before restarting PyCharm. Should we show a popup dialog to restart? :thinking:

ghost commented 11 months ago

Yes I think it might be a good Idea to show a popup that a restart is needed.

ttrei commented 11 months ago

I think the pyproject.toml discovery differs between the plugin and running ruff via command-line. https://docs.astral.sh/ruff/configuration/#config-file-discovery (permalink) (Note that passing the configuration file explicitly via --config disables the intelligent auto-discovery of the closest configuration file to the subject python file)

I observed the subject issue within a Pycharm project where the content root doesn't contain the .idea directory. Something like this:

~/PycharmProjects/foo-project/.idea/
~/dev/foo/ # this is the content root
~/dev/foo/.venv/ # virtual environment with ruff binary used by the Ruff plugin

"Ruff config file" was left empty in the plugin configuration. I placed ruff.toml both in ~/PycharmProjects/foo-project/ and in ~/dev/foo/, and tried to format some python files in ~/dev/foo/:

Note that there may be many content roots in a PyCharm project.

kamilos956 commented 4 months ago

I have the same issue. In the pyproject.toml file in the section tool.ruff.lint.per-file-ignores I have an entry "__init__.py" = ["PLC0414"], which in the Pycharm show me an error PLC0414. But when I run ruff with CLI everything is ok. Is it any update to this issue? I'm running on the WSL2 env. Feel free to ask me about project information, I would like to help to trace this error.