Sort lines within regions of a file.
Project description
Alphasort
Problem Statement
Keeping lines (alphabetically) sorted is always a pain. Say we have a long list that we want to maintain alphabetical sorting on (for the sake of readability and maintenance).
animals = [
"alligator",
"monkey",
"zebra",
]
Now We want to add “cat” to this list...
Either:
- dev remembers to insert in correct location (or insert anywhere and then sort)
- dev forgets and PR reviewers have to leave comment about it (just another thing prolonging PR time)
- the list falls out of sorting for a while then gets included as a refactor in a PR, adding many lines changed and inflating PR size
Introducing Alphasort
We add macros (directives) and a tool that can parse the files for this and to sort
animals = [
# alphasort: on
"apple",
"monkey",
"zebra",
# alphasort: off
]
And yes, it works on most other files too, including comment deliminators like // and more.
Setup
pip install alphasort
Usage
alphasort "./path/**/*.py"
Also recommend adding it
- to your IDE on-save commands
- to your pre-commit
- to your CI checks
P.S.
This is inspired by other such macros like:
# fmt: off
mylist = [3, 2, 1] # Black will not touch this line.
# fmt: on
I’m honestly surprised something like this doesn’t exist. But here it is now.
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 alphasort-0.1.17.tar.gz.
File metadata
- Download URL: alphasort-0.1.17.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.0 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53e6a0abb80fbb4647f5fbe05bb2aaf25deb35e6169a9ad72b58dff4b903e4f4
|
|
| MD5 |
8d67d1714f9207dfff2a38633d31e776
|
|
| BLAKE2b-256 |
d529a68d5f86aa1a2c709b908da26c0281f84203fe5f912dede4e759dce647ba
|
File details
Details for the file alphasort-0.1.17-py3-none-any.whl.
File metadata
- Download URL: alphasort-0.1.17-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.0 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d06bcdbdf5faeb85f4bdcaf7ef6fe66ff660fc5867d0e393c1d2937e11651b3a
|
|
| MD5 |
e8e6f6eb4632ddb194b45fa65506abd7
|
|
| BLAKE2b-256 |
09a55ea17b7c9bf84913798ffe55fd9bbf994bb3c1fcec30b927e86c99a517d6
|