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. Lines with # usort:skip
or # isort:skip
will also split blocks.
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
μsort 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.0a2.tar.gz
(15.7 kB
view hashes)
Built Distribution
usort-0.5.0a2-py3-none-any.whl
(11.0 kB
view hashes)