Formatter for pyproject.toml files
Project description
pyprojectsort
Formatter for pyproject.toml files.
This package enforces consistent formatting of pyproject.toml files, reducing merge request conflicts and saving time otherwise spent to format manually. It also contributes to a cleaner git history and more readable code; enhancing overall project organisation and maintainability. Experience a streamlined workflow, reduced errors, and improved code readability with pyprojectsort
.
Features
- Alphabetically sorts pyproject.toml by:
- section
- section key
- list value
- Reformats pyproject.toml to a standardised style
- line per list value
- double quotations
- trailing commas
- indentation
- end of file newline
Installation
pyprojectsort
is available via PyPI:
pip install pyprojectsort
Using pyprojectsort with pre-commit
To use as an automated git hook, add this to your .pre-commit-config.yaml
:
- repo: https://github.com/kieran-ryan/pyprojectsort
rev: v0.2.1
hooks:
- id: pyprojectsort
Examples
With the following pyproject.toml
:
[tool.ruff]
ignore = ["G004",
"T201",
"ANN"
]
[project]
name = 'pyprojectsort'
[tool.radon]
show_mi = true
exclude = "tests/*,venv/*"
total_average = true
show_complexity = true
[build-system]
build-backend = "flit.buildapi"
requires = ["flit"]
Run the package from within its directory:
pyprojectsort
The configuration will be reformatted as follows:
[build-system]
build-backend = "flit.buildapi"
requires = [
"flit",
]
[project]
name = "pyprojectsort"
[tool.radon]
exclude = "tests/*,venv/*"
show_complexity = true
show_mi = true
total_average = true
[tool.ruff]
ignore = [
"ANN",
"G004",
"T201",
]
The pyproject file path can alternatively be specified:
pyprojectsort ../pyproject.toml
Check formatting
The --check option can be used to determine whether your file would be reformatted.
pyprojectsort --check
If the file needs reformatting, the program exits with code 1. This is useful for pipeline integration as it prevents writing back changes so a clean repository is maintained for subsequent jobs.
License
pyprojectsort
is licensed under the MIT License.
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
Built Distribution
Hashes for pyprojectsort-0.2.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 945b7a9be4e069be2fae7d472f2ad0c83c93f9fc967a036b8bf71180304b25a0 |
|
MD5 | 3a8a5240261e62153b1f3d9c39251df7 |
|
BLAKE2b-256 | fceaaa399bdc424a8b16a65d741d1de3f0cf8b4a16591680ec5f30da52d0f5bd |