The python statement sorter
Project description
The python statement sorter.
Enforces topological sorting of top level python statements. Groups class members by types and enforces topological sorting of methods.
Compatible with and intended to complement isort and black.
Installation
SSort can be installed manually using pip.
$ pip install ssort
Usage
To check that a file is correctly sorted use the –check flag. –diff can be passed to see what changes ssort would make.
$ ssort --check --diff path/to/python_module.py
To allow ssort to rearrange your file, simply invoke with no extra flags. If ssort needs to make changes to a black conformant file, the result will not necessarily be black conformant. The result of running black on an ssort conformant file will always be ssort conformant. We recommend that you reformat using isort and black immediately _after_ running ssort.
$ ssort src/ tests/ setup.py; isort src/ tests/ setup.py; black src/ tests/ setup.py
Output
ssort will sort top level statements and statements in classes.
- When sorting top level statements, ssort follows three simple rules:
Statements must always be moved after the statements that they depend on, unless there is a cycle.
If there is a cycle, the order of statements within the cycle must not be changed.
If there is no dependency between statements then, to the greatest extent possible, the original order should be kept.
- ssort is more opinionated about the order of statements in classes:
Class attributes should be moved to the top of the class and must always be kept in their original order.
Lifecycle (__init__, __new__, etc) methods, and the methods they depend on, should go next.
Regular methods follow, dependencies always ahead of the methods that depend on them.
Other d’under methods should go at the end in a fixed order.
Links
Source code: https://github.com/bwhmather/ssort
Issue tracker: https://github.com/bwhmather/ssort/issues
License
The project is made available under the terms of the MIT license. See LICENSE for details.
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
File details
Details for the file ssort-0.5.0.tar.gz
.
File metadata
- Download URL: ssort-0.5.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb3e25047a76d3fc72ba2af61af3cd8ada23bc0c5457222e66aaae2a0a79e8d2 |
|
MD5 | ff84ab9e95da23d131d540a3d1bfa8c6 |
|
BLAKE2b-256 | 563dbe53f560e1224e4045b1dff4981acc8f96d977382968ebe6eb9cac5ce6cd |