Skip to main content

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


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)

Uploaded Source

Built Distribution

usort-0.5.0a1-py2.py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 2 Python 3

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