Skip to content

Commit

Permalink
add jsonschema 4.17.3 to asdf/_jsonschema
Browse files Browse the repository at this point in the history
- remove deprecated and unused jsonschema cli
- include tests (can be run with '--jsonschema' option)
- add ci label to run tests 'jsonschema'
  • Loading branch information
braingram committed Aug 1, 2023
1 parent 5da6d4a commit caf5a07
Show file tree
Hide file tree
Showing 636 changed files with 98,871 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ jobs:
python-version: 3.9
coverage: codecov

jsonschema:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
if: (github.repository == 'asdf-format/asdf' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'jsonschema')))
with:
submodules: false
# Any env name which does not start with `pyXY` will use this Python version.
default_python: '3.10'
envs: |
- linux: jsonschema
asdf-schemas:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ eggs
.eggs
parts
bin
!asdf/json/bin
var
sdist
develop-eggs
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: "asdf/(extern||_jsonschema)/.*"
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -39,7 +40,7 @@ repos:
rev: '1.0.0'
hooks:
- id: flynt
exclude: "asdf/extern/.*"
exclude: "asdf/(extern||_jsonschema)/.*"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.280'
Expand Down
3 changes: 1 addition & 2 deletions asdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
]


from jsonschema import ValidationError

from ._convenience import info
from ._version import version as __version__
from .asdf import AsdfFile
from .asdf import open_asdf as open
from .config import config_context, get_config
from .exceptions import ValidationError
from .stream import Stream
from .tags.core import IntegerType
from .tags.core.external_reference import ExternalArrayReference
19 changes: 19 additions & 0 deletions asdf/_jsonschema/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2013 Julian Berman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions asdf/_jsonschema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The files in this directory were originally cloned from

jsonschema 4.17.3

https://github.com/python-jsonschema/jsonschema/releases/tag/v4.17.3

See COPYING for use restrictions
55 changes: 55 additions & 0 deletions asdf/_jsonschema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
An implementation of JSON Schema for Python
The main functionality is provided by the validator classes for each of the
supported JSON Schema versions.
Most commonly, `asdf._jsonschema.validators.validate` is the quickest way to simply
validate a given instance under a schema, and will create a validator
for you.
"""
import warnings

from asdf._jsonschema._format import FormatChecker
from asdf._jsonschema._types import TypeChecker
from asdf._jsonschema.exceptions import (
ErrorTree,
FormatError,
RefResolutionError,
SchemaError,
ValidationError,
)
from asdf._jsonschema.protocols import Validator
from asdf._jsonschema.validators import (
Draft3Validator,
Draft4Validator,
Draft6Validator,
Draft7Validator,
Draft201909Validator,
Draft202012Validator,
RefResolver,
validate,
)


def __getattr__(name):
format_checkers = {
"draft3_format_checker": Draft3Validator,
"draft4_format_checker": Draft4Validator,
"draft6_format_checker": Draft6Validator,
"draft7_format_checker": Draft7Validator,
"draft201909_format_checker": Draft201909Validator,
"draft202012_format_checker": Draft202012Validator,
}
ValidatorForFormat = format_checkers.get(name)
if ValidatorForFormat is not None:
warnings.warn(
f"Accessing asdf._jsonschema.{name} is deprecated and will be "
"removed in a future release. Instead, use the FORMAT_CHECKER "
"attribute on the corresponding Validator.",
DeprecationWarning,
stacklevel=2,
)
return ValidatorForFormat.FORMAT_CHECKER

raise AttributeError(f"module {__name__} has no attribute {name}")
Loading

0 comments on commit caf5a07

Please sign in to comment.