Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading.
μsort is a safe, minimal import sorter. Its primary goal is to make no “dangerous” changes to code, and to make no changes on code style.
µfmt formats files in-memory, first with µsort and then with black, before writing any changes back to disk. This enables a combined, atomic step in CI/CD workflows for checking or formatting files, without any with conflict or intermediate changes between the import sorter and the code formatter.
µfmt requires Python 3.6 or newer. You can install it from PyPI:
$ pip install ufmt
If you want to prevent unexpected formatting changes that can break your CI workflow, make sure to pin your transitive dependencies–including black, µsort, and µfmt–to your preferred versions.
If you use
requirements.txt, this might look like:
black==20.8b1 ufmt==1.2 usort==0.6.3
To format one or more files or directories in place:
$ ufmt format <path> [<path> ...]
To validate files are formatted correctly, like for CI workflows:
$ ufmt check <path> [<path> ...]
To validate formatting and generate a diff of necessary changes:
$ ufmt diff <path> [<path> ...]