Hi all! We're in the process of replacing flake8,i...
# general
m
Hi all! We're in the process of replacing flake8,isort,black etc. with ruff and have now come to the point where we want to replace
isort
but are experiencing issues when doing so. As many before me have reported there seems to be confusion with what packages are 1st and 3rd party. I've tried many of the proposed solutions here and in the issue tracker by e.g. setting
src = ["src/*"]
but that seems to not be able to identify all 1st party packages. The only solution that seems to do exactly what is expected is to list all packages manually under:
Copy code
[tool.ruff.lint.isort]
known-first-party = [
  "my_package1",
  "my_package2",
  "my_packageN",
]
But surely that can't be the solution can it? Is there anything else I've missed that I can try out or is this still an open issue?
h
For isort itself that is the solution - their heuristics for detecting first party packages get defeated by Pants's sandboxing in some cases.
I guess ruff is purposely emulating those heuristics and so is also hitting the problems?
m
But wouldn't it be possible for pants to somehow inject those heuristics into the tools? I mean, pants should know what is considered 1st and 3rd party, no?
h
Yes, that would be possible, Pants does know this
If you're interested in doing that work, I can guide you through it
m
I might. Pants plugin development is still a bit intimidating to me 😅
h
It is not the easiest... 😓
m
I'll have a look at the ruff plugin code and might reach out if I have questions 🙂
h
The big question will, I assume, be how to find the list of first-party vs third-party packages. I think step 1 would be opening an issue in github to document the discussion
💯 1
b
I think https://github.com/pantsbuild/pants/issues/18410 is relevant, as is @bitter-ability-32190 ‘s WIP fix: https://github.com/pantsbuild/pants/pull/19869 (currently focused on isort but I suspect it can apply to ruff too) @bitter-ability-32190, what remains to get that working? Is it something someone could pick up and finish/apply to ruff?
b
I think we'd need to decide where the right tradeoff is, and write tests
m
I kind of found another solution. Setting
src = ["src/*"]
under
[tool.ruff]
and running
ruff
outside of Pants would render the expected result. Running it via Pants would still only treat the current target's source files as first party. I'm guessing there is some sandbox "issue" at play here. Is it possible to turn this off during formatting?