Skip to main content

sort lines

Alphabetize lines in a file.

This tool uses leading whitespace to delimit the lines that should be alphabetized. It is intended for use with Python code but should work with anything that has consistent indentation.

usage

Indicate that some lines should be alphabetized by including a comment on the line above (the comment must include # pragma: alphabetize).

# names.py
names = [  # pragma: alphabetize
    'Alice',
    'Bob',
    'Charlie',
    'David',
    'Eve',
]

Run this tool on the file:

sort-lines names.py

Indentation will be used to decide which lines need to be sorted. The first line after the pragma comment will set the indentation level and every subsequent line with the same amount of indentation will be included in the sorting. The first line with a different indentation(including blank lines) will indicate the end of the sorted lines.

Lines can be sorted case-insensitively by using the [ci] or [case-insensitive] options:

# names.py
names = [  # pragma: alphabetize[case-insensitive]
    'Alice',
    'bob',
    'Charlie',
    'david',
    'Eve',
]

Or by passing --case-insensitive on the command line.

pre-commit

This tool can be used with pre-commit:

repos:
-   repo: https://github.com/samueljsb/sort-lines
    rev: v0.3.0
    hooks:
    -   id: sort-lines

Metadata

Release files for sort-lines 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sort-lines 0.3.0
File Size Uploaded Provenance
sort_lines-0.3.0.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sort-lines 0.3.0
File Interpreter ABI Platform
sort_lines-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 7.7 kB

Release files / sort_lines-0.3.0.tar.gz

Download URL sort_lines-0.3.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0e2a70f9c562ca400f8b1bfef313bd469d933d7a6dcee0c3cc01551fe0dfd70b
BLAKE2b-256 checksum
How to use checksums
2a22bb06fb4a493219215b4ccdc81538880056350b70b6051b6b649660e1cd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / sort_lines-0.3.0-py2.py3-none-any.whl

Download URL sort_lines-0.3.0-py2.py3-none-any.whl
Size 4.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6600b1129de11157d1e0f2e16e8ae4c09a7bd70738194600350135207f35077c
BLAKE2b-256 checksum
How to use checksums
03cdc4cdc76e8bd30147a44ad1bdb6ad20cd879338dabb03dba129ff987a0ea2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Security for sort-lines 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page