I've been tinkering with the "fmt" goal. I have co...
# general
h
I've been tinkering with the "fmt" goal. I have configured black and isort as per the documentation. When I run:
./pants fmt ::
isort alters "subfolder/app.py" and properly separates my third party imports. If I run:
./pants fmt subfolder::
or
./pants fmt subfolder:lib
isort alters "subfolder/app.py" and puts all my imports back together. Guessing I should see the same behaviour in both cases? Running pants==2.2.0 and isort==5.7.0
h
Do you mean that isort and black are overwriting each other? You said isort twice and I'm double checking you meant that
If you did mean isort both times, you can use --black-skip when testing to reduce the number of variables
h
No I don't mean that black and isort are overriding each other. When I fmt "::" and then fmt "subfolder::" I get I get different results. Formatting with "::" works correctly, but "subfolder::" doesn't. I tried removing the black back end and got the same results.
h
h
I had already tried both of those suggestions. I added the pyproject.toml and also attempted to use the version of isort mentioned. The weird thing is that it does work, but only when formatting the entire repository.
h
Hm, I would suspect that it's because when you run on the whole repo, all the files are present so the import classifier algorithm behaves differently because it can see the whole universe, but running on the subdir does not have those other files present. Key detail that these run in chroots with only the relevant files included But I'm surprised isort 4 was still inconsistent? Last I checked, the issue is isort 5's new algorithm for import classification
h
I'll give it another shot.
h
Cool, it is almost certainly that tooltip happening here. Another thing to remember with the config file, you must set [isort].config for Pants to use it. Also, make sure it's at the build root and not somewhere like a build-support/ folder
h
yup that is what I had tried. Trying again now
So in pants.toml I have:
[isort]
config = "./isort.cfg"
version = "isort>=4.6,<5"
And in isort.cfg I have:
[settings]
known_first_party = ["lib_dash"]
default_section = "THIRDPARTY"
Same results
🤔 1
h
Hm I'm honestly not sure, that surprises me. I do remember I had to experiment a lot to get isort 5 working with Toolchain, but didn't have to with isort 4 My advice would be to remove Pants from the equation and experiment in a simple repo. Run
pex -m isort.main isort==5.6.x -o isort.pex
, then
./isort.pex **/*.py
. In that sample repo, solely have the code for
subfolder::
. Make sure imports are sorted how you want. Then add in
subfolder2
and ensure that all works That is, this is an isort problem, not a Pants problem, except that Pants surfaces the problem because of the chroot thing. So, the fix is getting isort to play nicely
h
Alright, thanks for the advice. I'll mess around with it some more and see what I can figure out.
h
Sounds good, please do report back if you find anything! I spent a lot of time on this question a few months ago but couldn't really be certain why my fix worked for Toolchain's repo - and apparently that fix doesn't work in all repos 🤷‍♂️
👍 1