A small, safe import sorter
Project description
μsort
μsort is a minimal import sorter. It should not make "dangerous" changes to your files, by detecting blocks which can be internally sorted. This simple heuristic works surprisingly well on real-world code:
import foo as os
import os
For this, we detect two sortable blocks because of the name shadowing.
import disable_network
disable_network.disable()
import b
For this, we detect two sortable blocks because of an intervening non-import statement.
Usage
To run on itself:
$ usort format --diff .
or to apply the changes remove --diff
.
Debugging
To see the blocks and sort keys:
$ usort list-imports --debug <filename>
Tests
Run
$ make venv
$ . .venv/bin/activate
$ make test
or
$ tox -p all
License
usort is MIT licensed, as found in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
usort-0.5.0a1.tar.gz
(14.4 kB
view hashes)
Built Distribution
Close
Hashes for usort-0.5.0a1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 381d1b1cabe4f9bae196da64ac356f8ac46c43e63d19757ae165f313867d250c |
|
MD5 | 641640a8a70cdc2ec74c220893e26f8b |
|
BLAKE2b-256 | 8264dda58ddf591ae706bb137e60c1daa38639fbe253f98516eee4d4be8bd10a |