https://pantsbuild.org/ logo
#general
Title
# general
h

high-egg-2153

02/23/2021, 2:56 PM
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

hundreds-father-404

02/23/2021, 3:11 PM
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

high-egg-2153

02/23/2021, 3:19 PM
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

hundreds-father-404

02/23/2021, 3:24 PM
h

high-egg-2153

02/23/2021, 3:39 PM
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

hundreds-father-404

02/23/2021, 3:46 PM
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

high-egg-2153

02/23/2021, 3:55 PM
I'll give it another shot.
h

hundreds-father-404

02/23/2021, 3:58 PM
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

high-egg-2153

02/23/2021, 4:01 PM
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

hundreds-father-404

02/23/2021, 4:52 PM
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

high-egg-2153

02/23/2021, 4:56 PM
Alright, thanks for the advice. I'll mess around with it some more and see what I can figure out.
h

hundreds-father-404

02/23/2021, 5:00 PM
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
6 Views