Skip to content

Commit 1432b27

Browse files
committed
move the JSON schema to the scisave library
1 parent 784a007 commit 1432b27

File tree

9 files changed

+13
-67
lines changed

9 files changed

+13
-67
lines changed

.github/envs/env_conda.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# logging and serialization
77
scilogger>=1.2.4
88
scisave>=1.4.5
9-
jsonschema>=4.23.0
109

1110
# numerical libraries
1211
numpy>=1.24.0

.github/envs/env_pypi.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# logging and serialization
77
scilogger>=1.2.4
88
scisave>=1.4.5
9-
jsonschema>=4.23.0
109

1110
# numerical libraries
1211
numpy>=1.24.0

.github/envs/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# logging and serialization
77
scilogger==1.2.4
88
scisave==1.4.5
9-
jsonschema==4.23.0
109

1110
# numerical libraries
1211
numpy==2.1.3

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ LABEL org.opencontainers.image.licenses="MPL-2.0 and others"
2222
RUN mamba install --yes --channel conda-forge \
2323
scilogger==1.2.4=pyhd8ed1ab_0 \
2424
scisave==1.4.5=pyhd8ed1ab_0 \
25-
jsonschema==4.23.0=pyhd8ed1ab_0 \
2625
numpy==2.1.3=py312h58c1407_0 \
2726
scipy==1.14.1=py312h62794b6_1 \
2827
joblib==1.4.2=pyhd8ed1ab_0 \

conda.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies:
3636
# logging and serialization
3737
- scilogger=1.2.4
3838
- scisave=1.4.5
39-
- jsonschema=4.23.0
4039
# numerical libraries
4140
- numpy=2.1.3
4241
- scipy=1.14.1

docs/content/technical.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Dependencies and Platforms
66

77
**PyPEEC** is entirely programmed in **Python 3** and has the following **dependencies**:
88

9-
* SciLogger, SciSave, and jsonschema (logging and serialization)
9+
* SciLogger and SciSave (logging and serialization)
1010
* NumPy, SciPy, and Joblib (basic numerical computing libraries)
1111
* Shapely and Rasterio (only used for the mesher, 2D shape manipulation)
1212
* Pillow (only used for the mesher, 2D image manipulation)

pypeec/lib_check/check_data_format.py

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
__license__ = "Mozilla Public License Version 2.0"
1818

1919
import importlib.resources
20-
import numpy as np
21-
import jsonschema
2220
import scisave
2321

2422
# static data folder
@@ -32,87 +30,41 @@
3230
SCHEMA_PLOTTER = scisave.load_config(folder.joinpath("schema_list_plotter.yaml"))
3331

3432

35-
def _get_strict_validator():
36-
"""
37-
Create a strict validator for numerics (integer and floating).
38-
Cast NumPy arrays as lists for the type check.
39-
"""
40-
41-
def get_int(_, instance):
42-
return np.issubdtype(type(instance), np.integer)
43-
44-
def get_float(_, instance):
45-
return np.issubdtype(type(instance), np.floating)
46-
47-
def get_array(_, instance):
48-
if isinstance(instance, np.ndarray):
49-
return jsonschema.Draft202012Validator.TYPE_CHECKER.is_type(instance.tolist(), "array")
50-
else:
51-
return jsonschema.Draft202012Validator.TYPE_CHECKER.is_type(instance, "array")
52-
53-
# custom type checker
54-
type_checker = jsonschema.Draft202012Validator.TYPE_CHECKER
55-
type_checker = type_checker.redefine("number", get_float)
56-
type_checker = type_checker.redefine("integer", get_int)
57-
type_checker = type_checker.redefine("array", get_array)
58-
59-
# custom validator
60-
StrictValidator = jsonschema.validators.extend(
61-
jsonschema.Draft202012Validator,
62-
type_checker=type_checker,
63-
)
64-
65-
return StrictValidator
66-
67-
68-
def _get_validate_schema(data, schema):
69-
"""
70-
Validate data with strict validator for numerics.
71-
"""
72-
73-
# get type checker
74-
StrictValidator = _get_strict_validator()
75-
76-
# validate schema
77-
validator = StrictValidator(schema=schema)
78-
validator.validate(data)
79-
80-
8133
def check_data_geometry(data_geometry):
8234
"""
8335
Check the mesher geometry data.
8436
"""
8537

86-
_get_validate_schema(data_geometry, SCHEMA_GEOMETRY)
38+
scisave.validate_schema(data_geometry, SCHEMA_GEOMETRY)
8739

8840

8941
def check_data_problem(data_problem):
9042
"""
9143
Check the solver problem data.
9244
"""
9345

94-
_get_validate_schema(data_problem, SCHEMA_PROBLEM)
46+
scisave.validate_schema(data_problem, SCHEMA_PROBLEM)
9547

9648

9749
def check_data_tolerance(data_tolerance):
9850
"""
9951
Check the solver tolerance data.
10052
"""
10153

102-
_get_validate_schema(data_tolerance, SCHEMA_TOLERANCE)
54+
scisave.validate_schema(data_tolerance, SCHEMA_TOLERANCE)
10355

10456

10557
def check_data_viewer(data_viewer):
10658
"""
10759
Check the viewer data.
10860
"""
10961

110-
_get_validate_schema(data_viewer, SCHEMA_VIEWER)
62+
scisave.validate_schema(data_viewer, SCHEMA_VIEWER)
11163

11264

11365
def check_data_plotter(data_tolerance):
11466
"""
11567
Check the plotter data.
11668
"""
11769

118-
_get_validate_schema(data_tolerance, SCHEMA_PLOTTER)
70+
scisave.validate_schema(data_tolerance, SCHEMA_PLOTTER)

pypeec/lib_check/check_data_options.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__copyright__ = "Thomas Guillod - Dartmouth College"
1010
__license__ = "Mozilla Public License Version 2.0"
1111

12-
import jsonschema
12+
import scisave
1313

1414

1515
def check_tag_list(data_check, tag_list):
@@ -29,7 +29,7 @@ def check_tag_list(data_check, tag_list):
2929
}
3030

3131
# validate base schema
32-
jsonschema.validate(instance=tag_list, schema=schema)
32+
scisave.validate_schema(tag_list, schema)
3333

3434
# check tag
3535
if tag_list is not None:
@@ -48,15 +48,15 @@ def check_plot_options(plot_mode, folder, name):
4848
"type": ["null", "string"],
4949
"enum": [None, "qt", "nb_int", "nb_std", "save", "debug"],
5050
}
51-
jsonschema.validate(instance=plot_mode, schema=schema)
51+
scisave.validate_schema(plot_mode, schema)
5252

5353
# check folder and name
5454
schema = {
5555
"type": ["null", "string"],
5656
"minLength": 1,
5757
}
58-
jsonschema.validate(instance=folder, schema=schema)
59-
jsonschema.validate(instance=name, schema=schema)
58+
scisave.validate_schema(folder, schema)
59+
scisave.validate_schema(name, schema)
6060

6161

6262
def check_data_voxel(data_voxel):
@@ -77,7 +77,7 @@ def check_data_voxel(data_voxel):
7777
}
7878

7979
# validate base schema
80-
jsonschema.validate(instance=data_voxel, schema=schema)
80+
scisave.validate_schema(data_voxel, schema)
8181

8282
# extract fields
8383
status = data_voxel["status"]
@@ -105,7 +105,7 @@ def check_data_solution(data_solution):
105105
}
106106

107107
# validate base schema
108-
jsonschema.validate(instance=data_solution, schema=schema)
108+
scisave.validate_schema(data_solution, schema)
109109

110110
# extract fields
111111
status = data_solution["status"]

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ classifiers = [
5353
dependencies = [
5454
"scilogger >= 1.2.4",
5555
"scisave >= 1.4.5",
56-
"jsonschema >= 4.23.0",
5756
"joblib >= 1.3.0",
5857
"numpy >= 1.24.0",
5958
"scipy >= 1.12.0",

0 commit comments

Comments
 (0)