File: generate_validation_code.py

package info (click to toggle)
setuptools 78.1.1-0.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,188 kB
  • sloc: python: 65,095; ansic: 204; makefile: 108; xml: 14
file content (39 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations

import itertools
import subprocess
import sys
from collections.abc import Iterable
from pathlib import Path


def generate_pyproject_validation(dest: Path, schemas: Iterable[Path]) -> bool:
    """
    Generates validation code for ``pyproject.toml`` based on JSON schemas and the
    ``validate-pyproject`` library.
    """
    schema_args = (("-t", f"{f.name.partition('.')[0]}={f}") for f in schemas)
    cmd = [
        sys.executable,
        "-m",
        "validate_pyproject.pre_compile",
        f"--output-dir={dest}",
        "--enable-plugins",
        "setuptools",
        "distutils",
        "--very-verbose",
        *itertools.chain.from_iterable(schema_args),
    ]
    subprocess.check_call(cmd)
    print(f"Validation code generated at: {dest}")
    return True


def main() -> bool:
    return generate_pyproject_validation(
        Path("setuptools/config/_validate_pyproject"),
        schemas=Path("setuptools/config").glob("*.schema.json"),
    )


__name__ == '__main__' and main()