-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Hello, I would like to add isort for automatic import sorting and black for general auto-formatting. I'm opening this ticket to first discuss and get the go-ahead.
Motivation
For imports, there is no uniform practice for how to order them, beyond compliance with PEP 8's separation of stdlib vs 3rd. party vs 1st. party import.
For general code formatting, there is a very clear code style but it requires developers to spend time enforcing it. There are also many files that violate the style guide.
This introduces a minor burden to readers who do not have consistent formatting and import orders and a burden to contributors to deal with formatting and import ordering.
Both isort and black offer automated, stable, and accessible mechanisms to fix this for very little effort.
Implementation plan
- Add
isort==4.3.20andblack==19.3b0torequirements-tests-py3.txt. - Setup
pyproject.tomlto configure both isort and black with a line length of 130 and so that isort works with black. - Update the
READMEto explain how to run both tools. - Update
.travis.ymlwith a new entry to run isort and black, both in check-only mode. - Run
isort -rc .to fix all current code. - Run
blackover all code.
Possible concern - git blame
The implementing PR will pollute the git history, but is mitigated by these factors:
- Once the tool is setup, there should never be future PRs dealing with import order because the tool will automatically enforce a good order.
- GitHub has the option "View prior commit" and most IDE tools like PyCharm have similar features.
- There is precedent for PRs that solely impact style, including an endorsement of this type of change in the contributing guide.