Skip to main content

Validation library and CLI tool for checking on 'pyproject.toml' files using JSON Schema

Project description

Project generated with PyScaffold Built Status ReadTheDocs Coveralls PyPI-Server

validate-pyproject

Automated checks on pyproject.toml powered by JSON Schema definitions

Description

With the approval of PEP 517 and PEP 518, the Python community shifted towards a strong focus on standardisation for packaging software, which allows more freedom when choosing tools during development and make sure packages created using different technologies can interoperate without the need for custom installation procedures.

This shift became even more clear when PEP 621 was also approved, as a standardised way of specifying project metadata and dependencies.

validate-pyproject was born in this context, with the mission of validating pyproject.toml files, and make sure they are compliant with the standards and PEPs. Behind the scenes, validate-pyproject relies on JSON Schema files, which, in turn, are also a standardised way of checking if a given data structure complies with a certain specification.

Usage

The easiest way of using validate-pyproject is via CLI. To get started, you need to install the package, which can be easily done using pipx:

$ pipx install 'validate-pyproject[all]'
# or to install and run in a single command
$ pipx run 'validate-pyproject[all]' --help

Now you can use validate-pyproject as a command line tool:

# in you terminal
$ validate-pyproject --help
$ validate-pyproject path/to/your/pyproject.toml

You can also use validate-pyproject in your Python scripts or projects:

# in your python code
from validate_pyproject import api, errors

# let's assume that you have access to a `loads` function
# responsible for parsing a string representing the TOML file
# (you can check the `toml` or `tomli` projects for that)
pyproject_as_dict = loads(pyproject_toml_str)

# now we can use validate-pyproject
validator = api.Validator()

try:
    validator(pyproject_as_dict)
except errors.ValidationError as ex:
    print(f"Invalid Document: {ex.message}")

To do so, don’t forget to add it to your virtual environment or specify it as a project or library dependency.

More details about validate-pyproject and its Python API can be found in our docs, which includes a description of the used JSON schemas, instructions for using it in a pre-compiled way and information about extending the validation with your own plugins.

Plugins

The validate-pyproject-schema-store plugin has a vendored copy of pyproject.toml related SchemaStore entries. You can even install this using the [store] extra:

$ pipx install ‘validate-pyproject[all,store]’

Some of the tools in SchemaStore also have integrated validate-pyproject plugins, like cibuildwheel and scikit-build-core. However, unless you want to pin an exact version of those tools, the SchemaStore copy is lighter weight than installing the entire package.

If you want to write a custom plugin for your tool, please consider also contributing a copy to SchemaStore.

pre-commit

validate-pyproject can be installed as a pre-commit hook:

---
repos:
  - repo: https://github.com/abravalheri/validate-pyproject
    rev: <insert current version here>
    hooks:
      - id: validate-pyproject
        # Optional extra validations from SchemaStore:
        additional_dependencies: ["validate-pyproject-schema-store[all]"]

By default, this pre-commit hook will only validate the pyproject.toml file at the root of the project repository. You can customize that by defining a custom regular expression pattern using the files parameter.

You can also use pre-commit autoupdate to update to the latest stable version of validate-pyproject (recommended).

You can also use validate-pyproject-schema-store as a pre-commit hook, which allows pre-commit to pin and update that instead of validate-pyproject itself.

Note

This project and its sister project ini2toml were initially created in the context of PyScaffold, with the purpose of helping migrating existing projects to PEP 621-style configuration when it is made available on setuptools. For details and usage information on PyScaffold see https://pyscaffold.org/.

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

validate_pyproject-0.25.tar.gz (118.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validate_pyproject-0.25-py3-none-any.whl (54.9 kB view details)

Uploaded Python 3

File details

Details for the file validate_pyproject-0.25.tar.gz.

File metadata

  • Download URL: validate_pyproject-0.25.tar.gz
  • Upload date:
  • Size: 118.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for validate_pyproject-0.25.tar.gz
Algorithm Hash digest
SHA256 e68c12d1cb0d8ddc269ffc42875a81727ddb7865000aa6d2f77d833b55c53f0b
MD5 ba92c0ca2e12902acb855ea9f51fb8bb
BLAKE2b-256 e7d845a82408619c306d0083afcf6142617201b2647a82e9a7d4c902e837274c

See more details on using hashes here.

File details

Details for the file validate_pyproject-0.25-py3-none-any.whl.

File metadata

File hashes

Hashes for validate_pyproject-0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 f9d05e2686beff82f9ea954f582306b036ced3d3feb258c1110f2c2a495b1981
MD5 e8b00c797b2c21a31e4d0d19487048fd
BLAKE2b-256 b7eee9c95cda829131f71a8dff5ce0406059fd16e591c074414e31ada19ba7c3

See more details on using hashes here.

Supported by

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