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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file usort-0.5.0a2.tar.gz.
File metadata
- Download URL: usort-0.5.0a2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbe1455c9997b26b64810d9206ff33c2552fac82934e0dcd1e3e01c8ab7fc201
|
|
| MD5 |
0b81489bc5c4fdbf7036a79c263ea803
|
|
| BLAKE2b-256 |
df7bccb39bb117f5735e5d0e4815a69d0e156326fba6b90243287a83be762f1f
|
File details
Details for the file usort-0.5.0a2-py3-none-any.whl.
File metadata
- Download URL: usort-0.5.0a2-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0811d0654cc9c05796a5254068447b7e354b36214b9e70e98e7ede3c9a54b416
|
|
| MD5 |
9f3a5534a79c0a711970896915a77010
|
|
| BLAKE2b-256 |
79ea71d9412bc7747d2c352faa311dfaf68d65484873c7f7e88f1b8657160231
|