pants
pants copied to clipboard
Bug Report: Pants-Ruff Import Order Bug
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.
This is just https://github.com/pantsbuild/pants/issues/15069 mapped onto ruff
lol :joy:
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.
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
(fromredis-py
)
Here we have renamed ai.backend.common.redis
to ai.backend.common.redis_helper
.
We just needed to add the known-first-party
option to fix our issue, thanks @achimnol
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.