Toml sorting library
Project description
toml-sort
A command line utility to sort and format your toml files. Requires Python 3.6+.
Read the latest documentation here: https://toml-sort.readthedocs.io/en/latest/
Installation
# With pip
pip install toml-sort
# With poetry
poetry add toml-sort
Motivation
This library sorts TOML files, providing the following features:
- Sort tables and Arrays of Tables (AoT)
- Option to sort non-tables / non-AoT's, or not
- Preserve inline comments
- Option to preserve top-level document comments, or not
- Standardize whitespace and indentation
I wrote this library/application because I couldn't find any "good" sorting utilities for TOML files. Now, I use this as part of my daily workflow. Hopefully it helps you too!
Usage
This project can be used as either a command line utility or a Python library.
Command line interface
Stdin -> Stdout : cat input.toml | toml-sort
Disk -> Disk : toml-sort -o output.toml input.toml
Linting : toml-sort --check input.toml
Inplace Disk : toml-sort --in-place input.toml
Example
The following example shows the input, and output, from the CLI with default options.
Unformatted, unsorted input
# My great TOML example
title = "The example"
[[a-section.hello]]
ports = [ 8001, 8001, 8002 ]
dob = 1979-05-27T07:32:00Z # First class dates? Why not?
[b-section]
date = "2018"
name = "Richard Stallman"
[[a-section.hello]]
ports = [ 80 ]
dob = 1920-05-27T07:32:00Z # Another date!
[a-section]
date = "2019"
name = "Samuel Roeca"
Formatted, sorted output
# My great TOML example
title = "The example"
[a-section]
date = "2019"
name = "Samuel Roeca"
[[a-section.hello]]
ports = [ 8001, 8001, 8002 ]
dob = 1979-05-27T07:32:00Z # First class dates? Why not?
[[a-section.hello]]
ports = [ 80 ]
dob = 1920-05-27T07:32:00Z # Another date!
[b-section]
date = "2018"
name = "Richard Stallman"
Local Development
Local development for this project is quite simple.
Dependencies
Install the following tools manually.
Recommended
Set up development environment
make setup
Run Tests
make test
Written by
Samuel Roeca, samuel.roeca@gmail.com
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
File details
Details for the file toml-sort-0.17.1.tar.gz
.
File metadata
- Download URL: toml-sort-0.17.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0 CPython/3.7.5 Linux/4.15.0-1065-oem
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee2500b449781cb809ad4ba016e8bbc407732228fe8f21827e1c29052493e9d |
|
MD5 | 5cf1b313a373469e14dcc9be9867301d |
|
BLAKE2b-256 | a69cc5f77546609955f978ea1be06f2e34f7d5d9a17adab58e70cac9f9744307 |
File details
Details for the file toml_sort-0.17.1-py3-none-any.whl
.
File metadata
- Download URL: toml_sort-0.17.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0 CPython/3.7.5 Linux/4.15.0-1065-oem
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eced8b77f36e92189fcdd201ffbdc0c1b1e71a03956e31921942b8cf6693be5 |
|
MD5 | 55aaee2d36bf23d19426d5de8dea19ad |
|
BLAKE2b-256 | 363115c4caeba6bab0137265bdf17ed0235b9d673105750a3b75465831510766 |