koxudaxi / ruff-pycharm-plugin

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

Handling monorepo setup #345

Closed jarikujansuu closed 4 months ago

jarikujansuu commented 6 months ago

Describe the bug

We got a monorepo setup so in a single repository we have multiple Python projects attached to it, so something like this

/ --- root is not a Python project but Typescript CDK project /service/X --- dockerised service /lambda/A. --- bunch of AWS Lambdas /lambda/B /lambda/C .... So all of those are separate Python setups with their own environments, all should have the same formatting rules

I tried enabling the Ruff plugin and the formatting feature and tested with that service "X". Without pointing to any configs it formatted the file with default settings instead of reading the current configs from the module pyproject.toml file.

If I then point the config file to service/X/pyproject.toml the code is formatted correctly but it doesn't recognize which are 3rd party and which are my imports so imports are moved to the wrong order

We have in pyproject.toml the following section, which doesn't seem to have any effect here

[tool.ruff.isort]
combine-as-imports = true
known-first-party = ["src", "tests"]

If I open the subproject (service/X) instead the root of the repository formatting seems to work correctly, so it reads the line length from pyproject.toml and also knows which are own and which are 3rd party imports

Expected behavior The plugin should read the configs from the subproject even if open the repository root in Pycharm.

Environments (please complete the following information):

koxudaxi commented 6 months ago

@jarikujansuu Thank you for creating the issue.

First, does ruff by itself without this plugin load the configuration file as expected? Because if you read here, ruff will properly go to load the closest pyproject.toml, so I don't think there is any need to do any detailed configuration here. https://docs.astral.sh/ruff/configuration/#config-file-discovery Unless you specify the config file path in the plugin configuration, the plugin will just run ruff from the project root.

koxudaxi commented 6 months ago

@jarikujansuu I have fixed the version 0.0.29 Thank you very much!!