Package: validate-pyproject
validate-pyprojectAutomated checks onpyproject.tomlpowered by JSON Schema definitionsImportantThis project isexperimentaland under active development.
Issue reports and contributions are very welcome.DescriptionWith the approval ofPEP 517andPEP 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 whenPEP 621was also approved, as a
standardised way of specifying project metadata and dependencies.validate-pyprojectwas born in this context, with the mission of validatingpyproject.tomlfiles, and make sure they are compliant with the standards
and PEPs. Behind the scenes,validate-pyprojectrelies onJSON Schemafiles, which, in turn, are also a standardised way of checking if a given data
structure complies with a certain specification.UsageThe easiest way of usingvalidate-pyprojectis via CLI.
To get started, you need to install the package, which can be easily done
usingpipx:$pipxinstall'validate-pyproject[all]'Now you can usevalidate-pyprojectas a command line tool:# in you terminal$validate-pyproject--help$validate-pyprojectpath/to/your/pyproject.tomlYou can also usevalidate-pyprojectin your Python scripts or projects:# in your python codefromvalidate_pyprojectimportapi,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-pyprojectvalidator=api.Validator()try:validator(pyproject_as_dict)excepterrors.ValidationErrorasex:print(f"Invalid Document:{ex.message}")To do so, don’t forget to add it to yourvirtual environmentor specify it as aprojectorlibrary dependency.NoteWhen you installvalidate-pyproject[all], the packagestomli,packagingandtrove-classifierswill be automatically pulled as
dependencies.tomliis a lightweight parser for TOML, whilepackagingandtrove-classifiersare used to validate aspects ofPEP
621.If you are only interested in using the Python API and wants to keep the
dependencies minimal, you can also installvalidate-pyproject(without the[all]extra dependencies group).If you don’t installtrove-classifiers,validate-pyprojectwill
try to download a list of valid classifiers directly from PyPI
(to prevent that, set the environment variableNO_NETWORKorVALIDATE_PYPROJECT_NO_NETWORK).On the other hand, ifvalidate-pyprojectcannot find a copy ofpackagingin your environment, the validation will fail.More details aboutvalidate-pyprojectand its Python API can be found inour docs, which includes a description of theused JSON schemas,
instructions for using it in apre-compiledwayand information about
extending the validation with your ownplugins.TipIf you consider contributing to this project, have a look on ourcontribution guides.pre-commitvalidate-pyprojectcan be installed as a pre-commit hook:---repos:-repo:https://github.com/abravalheri/validate-pyprojectrev:mainhooks:-id:validate-pyprojectBy default, thispre-commithook will only validate thepyproject.tomlfile at the root of the project repository.
You can customize that by defining acustom regular expression patternusing
thefilesparameter.You can also usepre-commitautoupdateto update to the latest stable
version ofvalidate-pyproject(recommended).NoteThis project and its sister projectini2tomlwere initially created in the
context of PyScaffold, with the purpose of helping migrating existing projects
toPEP 621-style configuration when it is made available onsetuptools.
For details and usage information on PyScaffold seehttps://pyscaffold.org/.