-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add schema and validate-pyproject support (#44)
* feat: add schema and validate-pyproject support Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * tests: add some tests for validate-pyproject Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
- Loading branch information
Showing
7 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# /// script | ||
# dependencies = ["pyyaml"] | ||
# /// | ||
from __future__ import annotations | ||
|
||
import json | ||
|
||
import yaml | ||
|
||
starter = """ | ||
$schema: http://json-schema.org/draft-07/schema# | ||
$id: https://json.schemastore.org/partial-check-sdist.json | ||
additionalProperties: false | ||
description: check-sdist's settings. | ||
type: object | ||
properties: | ||
sdist-only: | ||
description: Files that only are in the SDist. Gitignore style lines. | ||
type: array | ||
items: | ||
type: string | ||
git-only: | ||
description: Files that are only in Git. Gitignore style lines. | ||
type: array | ||
items: | ||
type: string | ||
default-ignore: | ||
description: Ignore some common files | ||
default: true | ||
type: boolean | ||
recurse-submodules: | ||
description: Look in all submodules too. | ||
default: true | ||
type: boolean | ||
""" | ||
|
||
schema = yaml.safe_load(starter) | ||
print(json.dumps(schema, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://json.schemastore.org/partial-check-sdist.json", | ||
"additionalProperties": false, | ||
"description": "check-sdist's settings.", | ||
"type": "object", | ||
"properties": { | ||
"sdist-only": { | ||
"description": "Files that only are in the SDist. Gitignore style lines.", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"git-only": { | ||
"description": "Files that are only in Git. Gitignore style lines.", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"default-ignore": { | ||
"description": "Ignore some common files", | ||
"default": true, | ||
"type": "boolean" | ||
}, | ||
"recurse-submodules": { | ||
"description": "Look in all submodules too.", | ||
"default": true, | ||
"type": "boolean" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import Any | ||
|
||
from .resources import resources | ||
|
||
|
||
def get_schema(tool_name: str = "check-sdist") -> dict[str, Any]: | ||
"Get the stored complete schema for check-sdist settings." | ||
assert tool_name == "check-sdist", "Only check-sdist is supported." | ||
|
||
with resources.joinpath("check-sdist.schema.json").open(encoding="utf-8") as f: | ||
return json.load(f) # type: ignore[no-any-return] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
import validate_pyproject.api | ||
|
||
|
||
def test_validate_pyproject_defaults(): | ||
example = { | ||
"tool": { | ||
"check-sdist": { | ||
"sdist-only": [], | ||
"git-only": [], | ||
"default-ignore": True, | ||
"recurse-submodules": True, | ||
} | ||
} | ||
} | ||
validator = validate_pyproject.api.Validator() | ||
assert validator(example) is not None | ||
|
||
|
||
def test_validate_pyproject_extra_key(): | ||
example: dict[str, object] = { | ||
"tool": { | ||
"check-sdist": { | ||
"sdists-only": [], | ||
} | ||
} | ||
} | ||
validator = validate_pyproject.api.Validator() | ||
with pytest.raises(validate_pyproject.error_reporting.ValidationError): | ||
validator(example) | ||
|
||
|
||
def test_validate_pyproject_invalid_value(): | ||
example = { | ||
"tool": { | ||
"check-sdist": { | ||
"sdist-only": [1], | ||
} | ||
} | ||
} | ||
validator = validate_pyproject.api.Validator() | ||
with pytest.raises(validate_pyproject.error_reporting.ValidationError): | ||
validator(example) |