pyprojectsort
Formatter for pyproject.toml files.
This package enforces consistent formatting of pyproject.toml files, reducing merge request conflicts and saving time otherwise spent on manual formatting. 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
- Alphanumerically 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.3.0
hooks:
- id: pyprojectsort
Examples
With the following pyproject.toml:
[tool.ruff]
ignore = ["G004",
"T201",
"ANN"
]
[project]
name = 'pyprojectsort'
authors = [
{ name = "Kieran Ryan" },
"Author Name <author@email.com>",
{name="Author Name"}
]
[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]
authors = [
"Author Name <author@email.com>",
{ name = "Author Name" },
{ name = "Kieran Ryan" },
]
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 an error code. This is useful for pipeline integration as it prevents writing back changes so that a clean repository is maintained for subsequent jobs.
The --diff option provides similar functionality but also displays any changes that would be made.
pyprojectsort --diff
The diff of an alphabetically reordered array will appear as follows:
@@ -6,8 +6,8 @@
[project]
authors = [
+ { name = "Author Name" },
{ name = "Kieran Ryan" },
- { name = "Author Name" },
]
License
pyprojectsort is licensed under the MIT License.
Metadata
Release files for pyprojectsort 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyprojectsort-0.4.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyprojectsort-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / pyprojectsort-0.4.0.tar.gz
| Download URL | pyprojectsort-0.4.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6a3a4efd86c085eb182fa125dce9ace6b817ad77bb2afbfbc31e52ce26cfa32
|
|
BLAKE2b-256 checksum How to use checksums |
fab584ce6207d1b66c07987ff65b5a88a523f58fee5508bbc5e92fff67c625cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Release files / pyprojectsort-0.4.0-py3-none-any.whl
| Download URL | pyprojectsort-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6209ac47e67cd1131d8ffbb711349d26a7e2d38429910fc5a7b1c998f7b13cee
|
|
BLAKE2b-256 checksum How to use checksums |
033429edefa451aadb2fefb302519260668e5253f65d356cb8d5ed96d830f78c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|