Skip to content

Commit

Permalink
hooks: add hook for jsonschema_specifications
Browse files Browse the repository at this point in the history
Required for jsonschema >= 4.18.0, where bundled specification files
have been moved into separate package.
  • Loading branch information
rokm committed Jul 7, 2023
1 parent 1faa548 commit c6d0847
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/614.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``jsonschema_specifications`` to collect the data files
that ``jsonschema`` v4.18.0 moved into a separate package.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ sympy==1.12
xyzservices==2023.5.0
mistune==3.0.1
pydantic==2.0.0
jsonschema==4.18.0

# ------------------- Platform (OS) specifics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

# This is needed to bundle draft3.json and draft4.json files that come
# with jsonschema module
# This is needed to bundle draft3.json and draft4.json files that come with jsonschema module.
# NOTE: with jsonschema >= 4.18.0, the specification files are part of jsonschema_specifications package, and are handled
# by the corresponding hook-jsonschema.

from PyInstaller.utils.hooks import collect_data_files, copy_metadata

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('jsonschema_specifications')
23 changes: 23 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,3 +1672,26 @@ def test_mistune(pyi_builder):
pyi_builder.test_source("""
import mistune
""")


@importorskip('jsonschema')
def test_jsonschema(pyi_builder):
pyi_builder.test_source("""
import jsonschema
# Sample schema
schema = {
"type" : "object",
"properties" : {
"price" : {"type" : "number"},
"name" : {"type" : "string"},
},
}
jsonschema.validate(instance={"name" : "Eggs", "price" : 3.38}, schema=schema)
try:
jsonschema.validate(instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema)
except jsonschema.ValidationError as e:
print(f"Validation error: {e}")
""")

0 comments on commit c6d0847

Please sign in to comment.