Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendorize jsonschema #1591

Merged
merged 12 commits into from
Aug 7, 2023
Merged
  •  
  •  
  •  
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ build
eggs
.eggs
parts
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ASDF Standard is at v1.6.0
by returning ``None`` in ``Converter.select_tag`` [#1561]
- Convert numpy scalars to python types during yaml encoding
to handle NEP51 changes for numpy 2.0 [#1605]
- Vendorize jsonschema 4.17.3 [#1591]

2.15.0 (2023-03-28)
-------------------
Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ There are two mailing lists for ASDF:
**F**\ ormat, information can be found
`here <https://seismic-data.org/>`__.

License
-------

ASDF is licensed under a BSD 3-clause style license. See `LICENSE.rst <LICENSE.rst>`_
for the `licenses folder <licenses>`_ for
licenses for any included software.

Contributing
------------

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include this in a more obvious location, something along the lines of astropy's top-level licenses directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great question. I never looked at the atropy top-level licenses (thanks for mentioning it!).

I stuck it in the source directory so that it would be packaged with the source (I'm not sure if this is necessary but it does seem like it should satisfy the requirement that the "copyright notice and this permission notice shall be included in all copies or substantial portions of the Software".

It doesn't appear that astropy packages the licenses they include in the top-level folder (looking at the DataTables license it mentions copyright by Allan Jardine and I find no mention of that name in the installed package).

What do you think about mentioning (perhaps in the README) that the vendorized jsonschema is subject to copyright and use restrictions by the license found in the _jsonschema_ submodule (or hopefully something more elegantly worded). I don't see a license notice at the moment so perhaps adding it to the end of the README and also mentioning the broader license in LICENSE?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good solution. I suspect people who are concerned about licenses are apt to look in the repo root but may not realize they need to drill down into other directories. A obvious pointer of some kind to nested license file would do the trick (could even check in a soft link?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a top level licenses directory with soft links to the included licenses (good idea!) and a link in the readme.


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
Loading