From 2bc5ce8ae1f1ad52909b4656444c1e9988e23cab Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 29 Jan 2024 10:56:48 -0500 Subject: [PATCH] feat: add schema and validate-pyproject support (#4181) Signed-off-by: Henry Schreiner Co-authored-by: Jelle Zijlstra --- .github/workflows/lint.yml | 5 + .github/workflows/test.yml | 2 +- .pre-commit-config.yaml | 11 +- CHANGES.md | 2 + pyproject.toml | 3 + scripts/generate_schema.py | 74 +++++++++++++ src/black/resources/__init__.py | 0 src/black/resources/black.schema.json | 149 ++++++++++++++++++++++++++ src/black/schema.py | 20 ++++ tests/test_schema.py | 17 +++ tox.ini | 10 +- 11 files changed, 288 insertions(+), 5 deletions(-) create mode 100644 scripts/generate_schema.py create mode 100644 src/black/resources/__init__.py create mode 100644 src/black/resources/black.schema.json create mode 100644 src/black/schema.py create mode 100644 tests/test_schema.py diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2d016cef7a6..8cb335bffb5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,3 +40,8 @@ jobs: - name: Format ourselves run: | tox -e run_self + + - name: Regenerate schema + run: | + tox -e generate_schema + git diff --exit-code diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55359a23303..fc274208258 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,4 +106,4 @@ jobs: python -m pip install -e ".[uvloop]" - name: Format ourselves - run: python -m black --check . + run: python -m black --check src/ tests/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13479565527..05569eed8db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,9 +42,9 @@ repos: rev: v1.8.0 hooks: - id: mypy - exclude: ^docs/conf.py - args: ["--config-file", "pyproject.toml"] - additional_dependencies: + exclude: ^(docs/conf.py|scripts/generate_schema.py)$ + args: [] + additional_dependencies: &mypy_deps - types-PyYAML - tomli >= 0.2.6, < 2.0.0 - click >= 8.1.0, != 8.1.4, != 8.1.5 @@ -56,6 +56,11 @@ repos: - types-commonmark - urllib3 - hypothesmith + - id: mypy + name: mypy (Python 3.10) + files: scripts/generate_schema.py + args: ["--python-version=3.10"] + additional_dependencies: *mypy_deps - repo: https://github.com/pre-commit/mirrors-prettier rev: v4.0.0-alpha.8 diff --git a/CHANGES.md b/CHANGES.md index 6da30afc707..4fd030df6df 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -45,6 +45,8 @@ +- Add a JSONSchema and provide a validate-pyproject entry-point (#4181) + ### Documentation