Skip to content
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

Bug Report: Pants-Ruff Import Order Bug #18410

Open
siggi84 opened this issue Mar 4, 2023 · 5 comments
Open

Bug Report: Pants-Ruff Import Order Bug #18410

siggi84 opened this issue Mar 4, 2023 · 5 comments
Labels
backend: Python Python backend-related issues bug

Comments

@siggi84
Copy link

siggi84 commented Mar 4, 2023

Describe the bug
The bug shows up when running ruff, with the isort (I) rules enabled, through pants.
When running the ruff --fix ... command on a file with both a first and third party import (unsorted), the import order is changed as expected. However, when running pants fmt fix lint ::, which also runs ruff, the import order remains unchanged due to wrong distinction between first and third party dependencies. The expected behavior is for ruff to give the same result whether executed directly or through pants.

Pants version
2.16.0.dev7

OS
Only tried this on linux (Ubuntu 22.10).

Additional info
A minimal example that shows the issue, how to reproduce it.

The issue can be mitigated by adding the source root entries in pants.toml to ruff.toml. Something like

src = ["src/python"]

However, having to specify the source roots in two places is not desirable.

@siggi84 siggi84 added the bug label Mar 4, 2023
@tdyas tdyas added the backend: Python Python backend-related issues label Mar 4, 2023
@thejcannon
Copy link
Member

This is just #15069 mapped onto ruff lol 😂

@thejcannon thejcannon added this to the 2.16.x milestone Mar 22, 2023
@huonw huonw removed this from the 2.16.x milestone Nov 26, 2023
@olivercoleman-switchdin
Copy link
Contributor

olivercoleman-switchdin commented Apr 8, 2024

Any news on this? This has been causing havoc with a new Pants-based monorepo implementation my company is slowly adopting 😬

Looks like #15069 was opened 2 years ago... is this something that is fixable? Or is there a workaround that works for ruff? Workarounds listed in #15069 don't seem to work for us.

We tried adding all the source folders to the src setting in a ruff.toml file (duplicating the source.root_patterns setting in pants.toml) to no avail.

@achimnol
Copy link
Sponsor

achimnol commented Apr 8, 2024

We also experienced a similar issue regarding:

  • src/ai/backend/manager/models/alembic vs. alembic

and workarounded this by adding such errorneously detetced packages to [tool.ruff.isort].known_third_party in pyproject.toml as in lablup/backend.ai#2005.

There was another case in the past:

  • src/ai/backend/common/redis vs. redis (from redis-py)

Here we have renamed ai.backend.common.redis to ai.backend.common.redis_helper.

@olivercoleman-switchdin
Copy link
Contributor

We just needed to add the known-first-party option to fix our issue, thanks @achimnol

@rajeshwar-nu
Copy link

We were able to fix this by setting the ruff setting fix to true. The behaviour after running pants fmt lint :: is that ruff sorts the imports, and finishes successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues bug
Projects
None yet
Development

No branches or pull requests

7 participants