imports: sort imports everywhere in Spack#24695
Conversation
|
I would probably tackle the list of issues here: https://github.com/spack/spack/pull/24695/checks?check_run_id=2982839061 before it's ready for review! |
4abf918 to
c44845f
Compare
|
Is this ready to merge after a rebase? |
|
@adamjstewart yeah but let the tests to run -- there were import errors last time -- want to make sure they're not lurking. |
|
Didn't actually review anything because GitHub can't load the changes, but I trust that isort didn't break much as long as the tests pass. I'll have to actually check out the black autoformatting branch to view that one as I'm more concerned about how it formats packages. |
|
@adamjstewart: the mac failure is due to The other failure is a circular import that I can’t reproduce. @trws saw it on #24718 (comment) and couldn’t reproduce it… if you have ideas let us know. @alalazo and I are working on reproducing it. |
We enabled import order checking in #23947, but fixing things manually drives people crazy. This used `spack style --fix --all` from #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it. This should go in after #24071, as it assumes we're using `isort`, not `flake8-import-order` to order things. `isort` seems to be more flexible and allows `llnl` mports to be in their own group before `spack` ones, so this seems like a good switch.
The style checks in the macOS builds behaved slightly differently from the other builds because we were installing the `pep8-naming` extension for some reason. -[x] remove `pep8-naming` from macOS installs
|
OK I think @alalazo and I have resolved the circular import thing -- it was not intuitive and it's not clear why this caused it. |
|
What was the cause of the circular import? I saw the fix, but it isn't clear to me how that could cause problems. P.S. We could enable https://pycqa.github.io/isort/docs/configuration/options.html#remove-redundant-aliases if we want to prevent it from happening again. |
|
Oh wow, |
|
Just found it. It was this issue, which was fixed in Python 3.7: TL; DR: before 3.7, there are issues with circular imports when using |
I think where there's not a good reason to be terse it's plenty clear to just say |
|
It seems like the only 100% safe thing to do in Python (i.e., the only thing resilient to adds, reorders, etc.) is going to be to |
|
That makes sense. Nice detective work. 👍 |
|
Ok everyone can rejoice -- all the imports are fixed and you can your own with |
|
@adamjstewart right now: |
|
Now we just need to merge that black PR so we can break every single open PR in Spack 😄 |

We enabled import order checking in #23947, but fixing things manually drives people crazy. This used
spack style --fix --allfrom #24071 to automatically sort everything in Spack so PR submitters won't have to deal with it.This should go in after #24071, as it assumes we're using
isort, notflake8-import-orderto order things.isortseems to be more flexible and allowsllnlmports to be in their own group beforespackones, so this seems like a good switch.On the plus side, this does make imports way more readable. I like being able to find them quickly at the tops of files.