Skip to main content

Safe, atomic formatting with black and µsort

Project description

µfmt

Safe, atomic formatting with black and µsort

version documentation changelog license build status code coverage

µfmt is a safe, atomic code formatter for Python built on top of black and µsort:

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.

Install

µ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

Usage

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> ...]

License

µfmt is copyright John Reese, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ufmt-1.2.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

ufmt-1.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ufmt-1.2.1.tar.gz.

File metadata

  • Download URL: ufmt-1.2.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for ufmt-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6f3c404383960394ae6e3fc89e998c0a5f9a1812d5e20ceff57289a3a8c9a25e
MD5 c8b7c2bbe88b88e88aa4f84f37d9e287
BLAKE2b-256 4a38a9e65d609e5e0728b0e2abc08eddcfbb3f86e7da63a7110893b3f90ee9bd

See more details on using hashes here.

File details

Details for the file ufmt-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: ufmt-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for ufmt-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb47853133eeb81c05e8cd1c8a892ff696c2e89da8cd9af6e106461fac2b6a7d
MD5 2fbb29d6798888a87c3a1cde83745541
BLAKE2b-256 41b2162225ca9129687761c7f9993c093ac3f1d6b6a5bdb832726f9a2a831747

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page