Skip to main content

Formatter for pyproject.toml files

Project description

pyprojectsort

PyPI Version LICENSE Python versions Supported platforms Code style: black Imports: isort Pipeline status pre-commit.ci status

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.2.2
  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.

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

pyprojectsort-0.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

pyprojectsort-0.3.0-py2.py3-none-any.whl (5.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyprojectsort-0.3.0.tar.gz.

File metadata

  • Download URL: pyprojectsort-0.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyprojectsort-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a5d315e0bd32f90f354315aa7c66654d3be809793fcd16c09afd7b38beb5d86a
MD5 cf4b3ce0bb248cdfed2eda0969b1c85c
BLAKE2b-256 8f5284630dcbdc7eebbf7f95a38c395765835f5d28acf54b1a5d4d4f596879c5

See more details on using hashes here.

File details

Details for the file pyprojectsort-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pyprojectsort-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2958a1a3a95f61cda61bc2c1d51b803b7f0e3e1c99793bff94929f0ac041b094
MD5 da3da4e1e961123171d8200fe0f81f38
BLAKE2b-256 d6871597bc0a6c3d2c4c0b90eeed17ade7f98e3653f432a03454519343331fed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page