Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# validate_pyproject package

## Subpackages

- validate_pyproject.plugins package
  - Module contents
    - `ErrorLoadingPlugin`
    - `PluginProtocol`
      - `PluginProtocol.fragment`
      - `PluginProtocol.help_text`
      - `PluginProtocol.id`
      - `PluginProtocol.schema`
      - `PluginProtocol.tool`
    - `PluginWrapper`
      - `PluginWrapper.fragment`
      - `PluginWrapper.help_text`
      - `PluginWrapper.id`
      - `PluginWrapper.schema`
      - `PluginWrapper.tool`
    - `iterate_entry_points()`
    - `list_from_entry_points()`
    - `load_from_entry_point()`
- validate_pyproject.pre_compile package
  - Submodules
  - validate_pyproject.pre_compile.cli module
    - `CliParams`
      - `CliParams.loglevel`
      - `CliParams.main_file`
      - `CliParams.output_dir`
      - `CliParams.plugins`
      - `CliParams.replacements`
      - `CliParams.store`
      - `CliParams.tool`
    - `JSON_dict()`
    - `ensure_dict()`
    - `main()`
    - `parser_spec()`
    - `run()`
  - Module contents
    - `copy_fastjsonschema_exceptions()`
    - `copy_module()`
    - `load_licenses()`
    - `pre_compile()`
    - `replace_text()`
    - `write_main()`
    - `write_notice()`
- validate_pyproject.vendoring package
  - Submodules
  - validate_pyproject.vendoring.cli module
    - `main()`
    - `run()`
  - Module contents
    - `vendorify()`

## 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])

  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[PluginProtocol] = ())

  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.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] = ())

  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

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

validate_pyproject.api.load_builtin_plugin(name: str) → Schema

validate_pyproject.api.read_text(package: str | module, resource: str) → str

## validate_pyproject.cli module

class validate_pyproject.cli.CliParams(input_file, plugins, tool, store, loglevel, dump_json)

  Bases: `NamedTuple`

  dump_json: bool

    Alias for field number 5

  input_file: List[TextIOBase]

    Alias for field number 0

  loglevel: int

    Alias for field number 4

  plugins: List[PluginWrapper]

    Alias for field number 1

  store: str

    Alias for field number 3

  tool: List[str]

    Alias for field number 2

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

  Bases: `RawTextHelpFormatter`

validate_pyproject.cli.critical_logging() → Generator[None, None, None]

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

validate_pyproject.cli.exceptions2exit() → Generator[None, None, None]

validate_pyproject.cli.main(args: Sequence[str] = ()) → int

  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

  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

validate_pyproject.cli.run(args: Sequence[str] = ()) → int

  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]

validate_pyproject.cli.setup_logging(loglevel: int) → None

  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)

  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() → Generator[None, None, None]

## validate_pyproject.errors module

exception validate_pyproject.errors.InvalidSchemaVersion(name: str, given_version: str, required_version: str)

  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

  Bases: `JsonSchemaException`

  Exception raised by generator of validation function.

exception validate_pyproject.errors.JsonSchemaException

  Bases: `ValueError`

  Base exception of `fastjsonschema` library.

exception validate_pyproject.errors.JsonSchemaValueException(message, value=None, name=None, definition=None, rule=None)

  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)

  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)

  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)

  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)

  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

## validate_pyproject.formats module

validate_pyproject.formats.int(value: int) → bool

validate_pyproject.formats.pep440(version: str) → bool

validate_pyproject.formats.pep508(value: str) → bool

validate_pyproject.formats.pep508_identifier(name: str) → bool

validate_pyproject.formats.pep508_versionspec(value: str) → bool

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

validate_pyproject.formats.pep517_backend_reference(value: str) → bool

validate_pyproject.formats.pep561_stub_name(value: str) → bool

validate_pyproject.formats.python_entrypoint_group(value: str) → bool

validate_pyproject.formats.python_entrypoint_name(value: str) → bool

validate_pyproject.formats.python_entrypoint_reference(value: str) → bool

validate_pyproject.formats.python_identifier(value: str) → bool

validate_pyproject.formats.python_module_name(value: str) → bool

validate_pyproject.formats.python_qualified_identifier(value: str) → bool

validate_pyproject.formats.uint(value: int) → bool

validate_pyproject.formats.uint16(value: int) → bool

validate_pyproject.formats.uint8(value: int) → bool

validate_pyproject.formats.url(value: str) → bool

## validate_pyproject.remote module

class validate_pyproject.remote.RemotePlugin(*, tool: str, schema: Schema, fragment: str = '')

  Bases: `object`

  classmethod from_str(tool_url: str) → Self
  classmethod from_url(tool: str, url: str) → Self

validate_pyproject.remote.load_store(pyproject_url: str) → Generator[RemotePlugin, None, None]

  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

class validate_pyproject.repo_review.VPP001

  Bases: `object`

  Validate pyproject.toml

  static check(pyproject: Dict[str, Any]) → str
  family = 'validate-pyproject'

validate_pyproject.repo_review.repo_review_checks() → Dict[str, VPP001]

validate_pyproject.repo_review.repo_review_families(pyproject: Dict[str, Any]) → Dict[str, Dict[str, str]]

## 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`]

class 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