validate_pyproject package#
Subpackages#
- validate_pyproject.plugins package
- validate_pyproject.pre_compile package
- validate_pyproject.vendoring package
Submodules#
validate_pyproject.api module#
Retrieve JSON schemas for validating dicts representing a pyproject.toml file.
- class validate_pyproject.api.AllPlugins(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
Enum- ALL_PLUGINS = 1#
- class validate_pyproject.api.RefHandler(registry: Mapping[str, Schema])[source]#
Bases:
Mapping[str,Callable[[str],Schema]]fastjsonschemaallows 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) (otherwiseurllibis 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[PluginProtocol] = ())[source]#
-
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
toolsubtables provided by the plugins.Since this object work as a mapping between each schema
$idand the schema itself, all schemas provided by plugins MUST have a top level$id.
- class validate_pyproject.api.Validator(plugins: ~typing.Sequence[PluginProtocol] | ~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': <validate_pyproject.formats._TroveClassifier object>, 'pep561-stub-name': <function pep561_stub_name>, '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>, 'uint8': <function uint8>, 'uint16': <function uint16>, 'uint': <function uint>, 'int': <function int>}), extra_validations: ~typing.Sequence[~typing.Callable[[~validate_pyproject.types.T], ~validate_pyproject.types.T]] = (<function validate_project_dynamic>,), *, extra_plugins: ~typing.Sequence[PluginProtocol] = ())[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 registry: SchemaRegistry#
validate_pyproject.cli module#
- class validate_pyproject.cli.CliParams(input_file, plugins, tool, store, loglevel, dump_json)[source]#
Bases:
NamedTuple- input_file: List[TextIOBase]#
Alias for field number 0
- 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() Generator[None, None, None][source]#
Make sure the logging level is set even before parsing the CLI args
- validate_pyproject.cli.main(args: Sequence[str] = ()) int#
Wrapper allowing
Translatorto be called in a CLI fashion.Instead of returning the value from
Translator.translate(), it prints the result to the givenoutput_fileorstdout.- 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] = ()) int[source]#
Wrapper allowing
Translatorto be called in a CLI fashion.Instead of returning the value from
Translator.translate(), it prints the result to the givenoutput_fileorstdout.- 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.error_reporting module#
- exception validate_pyproject.error_reporting.ValidationError(message, value=None, name=None, definition=None, rule=None)[source]#
Bases:
JsonSchemaValueExceptionReport violations of a given JSON schema.
This class extends
JsonSchemaValueExceptionby adding the following properties:summary: an improved version of theJsonSchemaValueExceptionerror 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
loggingconfiguration the exception message will be onlysummary(default) or a combination ofsummaryanddetails(when the logging level is set tologging.DEBUG).- details = ''#
- summary = ''#
validate_pyproject.errors module#
- exception validate_pyproject.errors.InvalidSchemaVersion(name: str, given_version: str, required_version: str)[source]#
Bases:
JsonSchemaDefinitionExceptionAll 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:
JsonSchemaExceptionException raised by generator of validation function.
- exception validate_pyproject.errors.JsonSchemaException[source]#
Bases:
ValueErrorBase exception of
fastjsonschemalibrary.
- exception validate_pyproject.errors.JsonSchemaValueException(message, value=None, name=None, definition=None, rule=None)[source]#
Bases:
JsonSchemaExceptionException raised by validation function. Available properties:
messagecontaining human-readable information what is wrong (e.g.data.property[index] must be smaller than or equal to 42),invalid
value(e.g.60),nameof a path in the data structure (e.g.data.property[index]),pathas an array in the data structure (e.g.['data', 'property', 'index']),the whole
definitionwhich thevaluehas to fulfil (e.g.{'type': 'number', 'maximum': 42}),rulewhich thevalueis 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:
JsonSchemaDefinitionExceptionAll 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:
JsonSchemaDefinitionExceptionAll 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:
JsonSchemaValueExceptionReport violations of a given JSON schema.
This class extends
JsonSchemaValueExceptionby adding the following properties:summary: an improved version of theJsonSchemaValueExceptionerror 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
loggingconfiguration the exception message will be onlysummary(default) or a combination ofsummaryanddetails(when the logging level is set tologging.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:
ValidationErrorAccording 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.formats module#
validate_pyproject.remote module#
- class validate_pyproject.remote.RemotePlugin(*, tool: str, schema: Schema, fragment: str = '')[source]#
Bases:
object
- validate_pyproject.remote.load_store(pyproject_url: str) Generator[RemotePlugin, None, None][source]#
Takes a URL / Path and loads the tool table, assuming it is a set of ref’s. Currently ignores “inline” sections. This is the format that SchemaStore (https://json.schemastore.org/pyproject.json) is in.
validate_pyproject.repo_review module#
validate_pyproject.types module#
- validate_pyproject.types.FormatValidationFn#
Should return
Truewhen the input string satisfies the format
- 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 apyproject.tomlfile.
- validate_pyproject.types.ValidationFn#
Custom validation function. It should receive as input a mapping corresponding to the whole
pyproject.tomlfile and raise afastjsonschema.JsonSchemaValueExceptionif it is not valid.alias of
Callable[[T],T]