Black code formatter
- Status: accepted
- Deciders:
- Date:
Context and problem statement
Archivematica code style is inconsistent and controversial. Formatting is a
distraction from content and a constant dilemma in our code review process.
The style guide described by PEP 8 is not specific enough and Python is too
flexible. Every project ends up with its own style and memorizing the rules is
hard.
With the recent rise of auto formatters such gofmt or Prettier, we see the
value of ceding control to an opinionated tool.
Considered options
- yapf - configurable formatter written by Google.
- autopep8 - relies on pycodestyle to determine what parts of the code
needs to be formatted.
- black - it focuses on making formatting totally transparent to the
developer.
Decision outcome
Chosen option: “black”, because:
- It prioritizes consistency over style.
- It can check that the reformatted code still produces a valid AST that is
equivalent to the original.
- Zero configuration, sane defaults.
- Adopted by popular projects such responder or pytest.
Links