Standardize Python import ordering #2986
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PBENCH-893
The ordering of Python import statements is a frequent topic of discussion during PR reviews. It's often not easy when writing code to determine whether a given module is "standard library" or not, and it's easy to accidentally add a new symbol out of order.
During a recent review, the
isort
utility was mentioned. I gave it a try but had some difficulty configuring it to be compatible with our black (despite the built-in "black" profile), and gave up.As an excuse to put off dealing with the necessity of breaking my development VM (and Varshini's dashboard testing), I decided to experiment a bit more to see if we can solve this issue "once and for all" as we've done with source format style in general by adopting
black
.I've now got a configuration (defined in our pyproject.toml file) that causes
isort
to generate output that makesblack
happy. (This was not trivial, sadly.) I've also replicated theblack
exclusion list, as that seemed to be appropriate.I've added
isort
along withblack
andflake8
to the lint tests in ourbuild.sh
script.NOTE: see https://pycqa.github.io/isort/docs/configuration/git_hook.html for instructions on adding
isort
to your git precommit hook. I've integrated theisort
extension (and configuration) into myvscode
. (Which will be much more useful once we get all modules to a standard baseline.)isort
changes 132 files in the tree, which are included in this PR. This includes obsolete legacy test files, which I decided weren't worth the effort of excluding.