validate_pyproject package#

Subpackages#

Submodules#

validate_pyproject.api module#

Retrieve JSON schemas for validating dicts representing a pyproject.toml file.

class validate_pyproject.api.AllPlugins(value)#

Bases: Enum

An enumeration.

ALL_PLUGINS = 1#
class validate_pyproject.api.RefHandler(registry: Mapping[str, Schema])[source]#

Bases: Mapping[str, Callable[[str], Schema]]

fastjsonschema allows passing a dict-like object to load external schema $ref``s. Such objects map the URI schema (e.g. ``http, https, ftp) into a function that receives the schema URI and returns the schema (as parsed JSON) (otherwise urllib is used and the URI is assumed to be a valid URL). This class will ensure all the URIs are loaded from the local registry.

class validate_pyproject.api.SchemaRegistry(plugins: Sequence[PluginWrapper] = ())[source]#

Bases: Mapping[str, Schema]

Repository of parsed JSON Schemas used for validating a pyproject.toml.

During instantiation the schemas equivalent to PEP 517, PEP 518 and PEP 621 will be combined with the schemas for the tool subtables provided by the plugins.

Since this object work as a mapping between each schema $id and the schema itself, all schemas provided by plugins MUST have a top level $id.

property main: str#

Top level schema for validating a pyproject.toml file

property spec_version: str#

Version of the JSON Schema spec in use

class validate_pyproject.api.Validator(plugins: ~typing.Union[~typing.Sequence[PluginWrapper], ~validate_pyproject.api.AllPlugins] = AllPlugins.ALL_PLUGINS, format_validators: ~typing.Mapping[str, ~typing.Callable[[str], bool]] = mappingproxy({'chain': <class 'itertools.chain'>, 'pep440': <function pep440>, 'pep508-identifier': <function pep508_identifier>, 'pep508': <function pep508>, 'pep508-versionspec': <function pep508_versionspec>, 'pep517-backend-reference': <function pep517_backend_reference>, 'trove-classifier': <function trove_classifier>, 'url': <function url>, 'python-identifier': <function python_identifier>, 'python-qualified-identifier': <function python_qualified_identifier>, 'python-module-name': <function python_module_name>, 'python-entrypoint-group': <function python_entrypoint_group>, 'python-entrypoint-name': <function python_entrypoint_name>, 'python-entrypoint-reference': <function python_entrypoint_reference>}), extra_validations: ~typing.Sequence[~typing.Callable[[~validate_pyproject.types.T], ~validate_pyproject.types.T]] = (<function validate_project_dynamic>,))[source]#

Bases: object

property extra_validations: Sequence[Callable[[T], T]]#

List of extra validation functions that run after the JSON Schema check

property formats: Mapping[str, Callable[[str], bool]]#

Mapping between JSON Schema formats and functions that validates them

property generated_code: str#
property registry: SchemaRegistry#
property schema: Schema#

Top level pyproject.toml JSON Schema

validate_pyproject.api.load(name: str, package: str = 'validate_pyproject', ext: str = '.schema.json') Schema[source]#

Load the schema from a JSON Schema file. The returned dict-like object is immutable.

validate_pyproject.api.load_builtin_plugin(name: str) Schema[source]#

validate_pyproject.cli module#

class validate_pyproject.cli.CliParams(input_file, plugins, loglevel, dump_json)[source]#

Bases: tuple

dump_json: bool#

Alias for field number 3

input_file: List[TextIOBase]#

Alias for field number 0

loglevel: int#

Alias for field number 2

plugins: List[PluginWrapper]#

Alias for field number 1

class validate_pyproject.cli.Formatter(prog, indent_increment=2, max_help_position=24, width=None)[source]#

Bases: RawTextHelpFormatter

validate_pyproject.cli.critical_logging()[source]#

Make sure the logging level is set even before parsing the CLI args

validate_pyproject.cli.exceptions2exit()[source]#
validate_pyproject.cli.main(args: Sequence[str] = ())#

Wrapper allowing Translator to be called in a CLI fashion.

Instead of returning the value from Translator.translate(), it prints the result to the given output_file or stdout.

Parameters

args (List[str]) – command line parameters as list of strings (for example ["--verbose", "setup.cfg"]).

validate_pyproject.cli.parse_args(args: ~typing.Sequence[str], plugins: ~typing.Sequence[~validate_pyproject.plugins.PluginWrapper], description: str = 'Validate a given TOML file', get_parser_spec: ~typing.Callable[[~typing.Sequence[~validate_pyproject.plugins.PluginWrapper]], ~typing.Dict[str, dict]] = <function __meta__>, params_class: ~typing.Type[~validate_pyproject.cli.T] = <class 'validate_pyproject.cli.CliParams'>) T[source]#

Parse command line parameters

Parameters

args – command line parameters as list of strings (for example ["--help"]).

Returns: command line parameters namespace

validate_pyproject.cli.plugins_help(plugins: Sequence[PluginWrapper]) str[source]#
validate_pyproject.cli.run(args: Sequence[str] = ())[source]#

Wrapper allowing Translator to be called in a CLI fashion.

Instead of returning the value from Translator.translate(), it prints the result to the given output_file or stdout.

Parameters

args (List[str]) – command line parameters as list of strings (for example ["--verbose", "setup.cfg"]).

validate_pyproject.cli.select_plugins(plugins: Sequence[PluginWrapper], enabled: Sequence[str] = (), disabled: Sequence[str] = ()) List[PluginWrapper][source]#
validate_pyproject.cli.setup_logging(loglevel: int)[source]#

Setup basic logging

Parameters

loglevel – minimum loglevel for emitting messages

validate_pyproject.error_reporting module#

exception validate_pyproject.error_reporting.ValidationError(message, value=None, name=None, definition=None, rule=None)[source]#

Bases: JsonSchemaValueException

Report violations of a given JSON schema.

This class extends JsonSchemaValueException by adding the following properties:

  • summary: an improved version of the JsonSchemaValueException error message with only the necessary information)

  • details: more contextual information about the error like the failing schema itself and the value that violates the schema.

Depending on the level of the verbosity of the logging configuration the exception message will be only summary (default) or a combination of summary and details (when the logging level is set to logging.DEBUG).

details = ''#
summary = ''#
validate_pyproject.error_reporting.detailed_errors()[source]#

validate_pyproject.errors module#

exception validate_pyproject.errors.InvalidSchemaVersion(name: str, given_version: str, required_version: str)[source]#

Bases: JsonSchemaDefinitionException

All schemas used in the validator should be specified using the same version as the toplevel schema ({version!r}).

Schema for {name!r} has version {given!r}.

exception validate_pyproject.errors.JsonSchemaDefinitionException[source]#

Bases: JsonSchemaException

Exception raised by generator of validation function.

exception validate_pyproject.errors.JsonSchemaException[source]#

Bases: ValueError

Base exception of fastjsonschema library.

exception validate_pyproject.errors.JsonSchemaValueException(message, value=None, name=None, definition=None, rule=None)[source]#

Bases: JsonSchemaException

Exception raised by validation function. Available properties:

  • message containing human-readable information what is wrong (e.g. data.property[index] must be smaller than or equal to 42),

  • invalid value (e.g. 60),

  • name of a path in the data structure (e.g. data.property[index]),

  • path as an array in the data structure (e.g. ['data', 'property', 'index']),

  • the whole definition which the value has to fulfil (e.g. {'type': 'number', 'maximum': 42}),

  • rule which the value is breaking (e.g. maximum)

  • and rule_definition (e.g. 42).

Changed in version 2.14.0: Added all extra properties.

property path#
property rule_definition#
exception validate_pyproject.errors.SchemaMissingId(reference: str)[source]#

Bases: JsonSchemaDefinitionException

All schemas used in the validator MUST define a unique toplevel “$id”. No “$id” was found for schema associated with {reference!r}.

exception validate_pyproject.errors.SchemaWithDuplicatedId(schema_id: str)[source]#

Bases: JsonSchemaDefinitionException

All schemas used in the validator MUST define a unique toplevel “$id”. $id = {schema_id!r} was found at least twice.

exception validate_pyproject.errors.ValidationError(message, value=None, name=None, definition=None, rule=None)[source]#

Bases: JsonSchemaValueException

Report violations of a given JSON schema.

This class extends JsonSchemaValueException by adding the following properties:

  • summary: an improved version of the JsonSchemaValueException error message with only the necessary information)

  • details: more contextual information about the error like the failing schema itself and the value that violates the schema.

Depending on the level of the verbosity of the logging configuration the exception message will be only summary (default) or a combination of summary and details (when the logging level is set to logging.DEBUG).

details = ''#
summary = ''#

validate_pyproject.extra_validations module#

The purpose of this module is implement PEP 621 validations that are difficult to express as a JSON Schema (or that are not supported by the current JSON Schema library).

exception validate_pyproject.extra_validations.RedefiningStaticFieldAsDynamic(message, value=None, name=None, definition=None, rule=None)[source]#

Bases: ValidationError

According to PEP 621:

Build back-ends MUST raise an error if the metadata specifies a field statically as well as being listed in dynamic.

validate_pyproject.extra_validations.validate_project_dynamic(pyproject: T) T[source]#

validate_pyproject.formats module#

validate_pyproject.formats.pep440(version: str) bool[source]#
validate_pyproject.formats.pep508(value: str) bool[source]#
validate_pyproject.formats.pep508_identifier(name: str) bool[source]#
validate_pyproject.formats.pep508_versionspec(value: str) bool[source]#

Expression that can be used to specify/lock versions (including ranges)

validate_pyproject.formats.pep517_backend_reference(value: str) bool[source]#
validate_pyproject.formats.python_entrypoint_group(value: str) bool[source]#
validate_pyproject.formats.python_entrypoint_name(value: str) bool[source]#
validate_pyproject.formats.python_entrypoint_reference(value: str) bool[source]#
validate_pyproject.formats.python_identifier(value: str) bool[source]#
validate_pyproject.formats.python_module_name(value: str) bool[source]#
validate_pyproject.formats.python_qualified_identifier(value: str) bool[source]#
validate_pyproject.formats.trove_classifier(value: str) bool[source]#
validate_pyproject.formats.url(value: str) bool[source]#

validate_pyproject.types module#

validate_pyproject.types.FormatValidationFn#

Should return True when the input string satisfies the format

alias of Callable[[str], bool]

validate_pyproject.types.Plugin#

A plugin is something that receives the name of a tool sub-table (as defined in PEPPEP621) and returns a Schema.

For example plugin("setuptools") should return the JSON schema for the [tool.setuptools] table of a pyproject.toml file.

alias of Callable[[str], Schema]

validate_pyproject.types.Schema#

JSON Schema represented as a Python dict

alias of Mapping

validate_pyproject.types.ValidationFn#

Custom validation function. It should receive as input a mapping corresponding to the whole pyproject.toml file and raise a fastjsonschema.JsonSchemaValueException if it is not valid.

alias of Callable[[T], T]

Module contents#