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


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usort-0.5.0a2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

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

Hashes for usort-0.5.0a2.tar.gz
Algorithm Hash digest
SHA256 cbe1455c9997b26b64810d9206ff33c2552fac82934e0dcd1e3e01c8ab7fc201
MD5 0b81489bc5c4fdbf7036a79c263ea803
BLAKE2b-256 df7bccb39bb117f5735e5d0e4815a69d0e156326fba6b90243287a83be762f1f

See more details on using hashes here.

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

Hashes for usort-0.5.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 0811d0654cc9c05796a5254068447b7e354b36214b9e70e98e7ede3c9a54b416
MD5 9f3a5534a79c0a711970896915a77010
BLAKE2b-256 79ea71d9412bc7747d2c352faa311dfaf68d65484873c7f7e88f1b8657160231

See more details on using hashes here.

Supported by

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