precice-adapter-schema 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- precice_adapter_schema-0.4.1/LICENSE +21 -0
- precice_adapter_schema-0.4.1/PKG-INFO +81 -0
- precice_adapter_schema-0.4.1/README.md +61 -0
- precice_adapter_schema-0.4.1/precice_adapter_schema.egg-info/PKG-INFO +81 -0
- precice_adapter_schema-0.4.1/precice_adapter_schema.egg-info/SOURCES.txt +12 -0
- precice_adapter_schema-0.4.1/precice_adapter_schema.egg-info/dependency_links.txt +1 -0
- precice_adapter_schema-0.4.1/precice_adapter_schema.egg-info/requires.txt +4 -0
- precice_adapter_schema-0.4.1/precice_adapter_schema.egg-info/top_level.txt +1 -0
- precice_adapter_schema-0.4.1/preciceadapterschema/__init__.py +3 -0
- precice_adapter_schema-0.4.1/preciceadapterschema/precice_adapter_config.schema.json +211 -0
- precice_adapter_schema-0.4.1/preciceadapterschema/validate.py +35 -0
- precice_adapter_schema-0.4.1/pyproject.toml +38 -0
- precice_adapter_schema-0.4.1/setup.cfg +4 -0
- precice_adapter_schema-0.4.1/tests/test_validate.py +74 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Felix Neubauer, Frédéric Simonis, The preCICE developers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: precice-adapter-schema
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Validation utility for preCICE adapter configurations
|
|
5
|
+
Author-email: preCICE developers <info@precice.org>
|
|
6
|
+
Project-URL: Homepage, https://github.com/precice/adapter-schema
|
|
7
|
+
Project-URL: Repository, https://github.com/precice/adapter-schema
|
|
8
|
+
Keywords: preCICE,adapter,validation,schema
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: jsonschema>=4.0.0
|
|
18
|
+
Requires-Dist: importlib-resources>=5.0.0; python_version < "3.9"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# preCICE Adapter Schema
|
|
22
|
+
|
|
23
|
+
Here the adapter configuration schema is stored, together with validation utility.
|
|
24
|
+
|
|
25
|
+
A schema ...
|
|
26
|
+
|
|
27
|
+
- defines how a configuration file looks like (thus replaces any explicit documentation).
|
|
28
|
+
- enables interoperability (through standardization).
|
|
29
|
+
- simplifies auto-generation.
|
|
30
|
+
- enables tooling support (e.g. IDEs or GUIs).
|
|
31
|
+
- enables automatic LLM-based conversion from and to other configuration languages.
|
|
32
|
+
- ...
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Install the package using pip:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install preciceadapterschema
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For development, install in editable mode:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install -e .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
The `preciceadapterschema` package provides a `validate` function to validate preCICE adapter configurations against the JSON schema.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import preciceadapterschema
|
|
54
|
+
|
|
55
|
+
# Your configuration data
|
|
56
|
+
config_data = {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Validate the configuration
|
|
60
|
+
try:
|
|
61
|
+
preciceadapterschema.validate(config_data)
|
|
62
|
+
print("Configuration is valid!")
|
|
63
|
+
except Exception as e:
|
|
64
|
+
print(f"Validation failed: {e}")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The schema file (`precice_adapter_config.schema.json`) is included in the package and loaded automatically by the `validate` function.
|
|
68
|
+
|
|
69
|
+
## Configuring preCICE Adapters
|
|
70
|
+
|
|
71
|
+
We recommend using [MetaConfigurator](https://metaconfigurator.org/?schema=https://github.com/precice/adapter-schema/blob/main/preciceadapterschema/precice_adapter_config.schema.json&settings=https://github.com/precice/adapter-schema/blob/main/metaconfigurator_settings.json) to create and edit preCICE adapter configurations. It provides a user-friendly interface and ensures that your configurations are always valid according to the schema.
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
### Running Tests
|
|
76
|
+
|
|
77
|
+
Run tests using unittest:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
python -m unittest discover -s tests -v
|
|
81
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# preCICE Adapter Schema
|
|
2
|
+
|
|
3
|
+
Here the adapter configuration schema is stored, together with validation utility.
|
|
4
|
+
|
|
5
|
+
A schema ...
|
|
6
|
+
|
|
7
|
+
- defines how a configuration file looks like (thus replaces any explicit documentation).
|
|
8
|
+
- enables interoperability (through standardization).
|
|
9
|
+
- simplifies auto-generation.
|
|
10
|
+
- enables tooling support (e.g. IDEs or GUIs).
|
|
11
|
+
- enables automatic LLM-based conversion from and to other configuration languages.
|
|
12
|
+
- ...
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install the package using pip:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install preciceadapterschema
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For development, install in editable mode:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
The `preciceadapterschema` package provides a `validate` function to validate preCICE adapter configurations against the JSON schema.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import preciceadapterschema
|
|
34
|
+
|
|
35
|
+
# Your configuration data
|
|
36
|
+
config_data = {
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Validate the configuration
|
|
40
|
+
try:
|
|
41
|
+
preciceadapterschema.validate(config_data)
|
|
42
|
+
print("Configuration is valid!")
|
|
43
|
+
except Exception as e:
|
|
44
|
+
print(f"Validation failed: {e}")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The schema file (`precice_adapter_config.schema.json`) is included in the package and loaded automatically by the `validate` function.
|
|
48
|
+
|
|
49
|
+
## Configuring preCICE Adapters
|
|
50
|
+
|
|
51
|
+
We recommend using [MetaConfigurator](https://metaconfigurator.org/?schema=https://github.com/precice/adapter-schema/blob/main/preciceadapterschema/precice_adapter_config.schema.json&settings=https://github.com/precice/adapter-schema/blob/main/metaconfigurator_settings.json) to create and edit preCICE adapter configurations. It provides a user-friendly interface and ensures that your configurations are always valid according to the schema.
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
### Running Tests
|
|
56
|
+
|
|
57
|
+
Run tests using unittest:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m unittest discover -s tests -v
|
|
61
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: precice-adapter-schema
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Validation utility for preCICE adapter configurations
|
|
5
|
+
Author-email: preCICE developers <info@precice.org>
|
|
6
|
+
Project-URL: Homepage, https://github.com/precice/adapter-schema
|
|
7
|
+
Project-URL: Repository, https://github.com/precice/adapter-schema
|
|
8
|
+
Keywords: preCICE,adapter,validation,schema
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: jsonschema>=4.0.0
|
|
18
|
+
Requires-Dist: importlib-resources>=5.0.0; python_version < "3.9"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# preCICE Adapter Schema
|
|
22
|
+
|
|
23
|
+
Here the adapter configuration schema is stored, together with validation utility.
|
|
24
|
+
|
|
25
|
+
A schema ...
|
|
26
|
+
|
|
27
|
+
- defines how a configuration file looks like (thus replaces any explicit documentation).
|
|
28
|
+
- enables interoperability (through standardization).
|
|
29
|
+
- simplifies auto-generation.
|
|
30
|
+
- enables tooling support (e.g. IDEs or GUIs).
|
|
31
|
+
- enables automatic LLM-based conversion from and to other configuration languages.
|
|
32
|
+
- ...
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Install the package using pip:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install preciceadapterschema
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For development, install in editable mode:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install -e .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
The `preciceadapterschema` package provides a `validate` function to validate preCICE adapter configurations against the JSON schema.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import preciceadapterschema
|
|
54
|
+
|
|
55
|
+
# Your configuration data
|
|
56
|
+
config_data = {
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Validate the configuration
|
|
60
|
+
try:
|
|
61
|
+
preciceadapterschema.validate(config_data)
|
|
62
|
+
print("Configuration is valid!")
|
|
63
|
+
except Exception as e:
|
|
64
|
+
print(f"Validation failed: {e}")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The schema file (`precice_adapter_config.schema.json`) is included in the package and loaded automatically by the `validate` function.
|
|
68
|
+
|
|
69
|
+
## Configuring preCICE Adapters
|
|
70
|
+
|
|
71
|
+
We recommend using [MetaConfigurator](https://metaconfigurator.org/?schema=https://github.com/precice/adapter-schema/blob/main/preciceadapterschema/precice_adapter_config.schema.json&settings=https://github.com/precice/adapter-schema/blob/main/metaconfigurator_settings.json) to create and edit preCICE adapter configurations. It provides a user-friendly interface and ensures that your configurations are always valid according to the schema.
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
### Running Tests
|
|
76
|
+
|
|
77
|
+
Run tests using unittest:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
python -m unittest discover -s tests -v
|
|
81
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
precice_adapter_schema.egg-info/PKG-INFO
|
|
5
|
+
precice_adapter_schema.egg-info/SOURCES.txt
|
|
6
|
+
precice_adapter_schema.egg-info/dependency_links.txt
|
|
7
|
+
precice_adapter_schema.egg-info/requires.txt
|
|
8
|
+
precice_adapter_schema.egg-info/top_level.txt
|
|
9
|
+
preciceadapterschema/__init__.py
|
|
10
|
+
preciceadapterschema/precice_adapter_config.schema.json
|
|
11
|
+
preciceadapterschema/validate.py
|
|
12
|
+
tests/test_validate.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
preciceadapterschema
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/precice/adapter-schema/releases/download/v0.4/precice_adapter_config_schema.json",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"metaConfigurator": {
|
|
6
|
+
"aiExportFormats": {
|
|
7
|
+
"OpenFOAM": {
|
|
8
|
+
"url": "https://github.com/precice/adapter-schema/blob/main/export-formats/open-foam-example",
|
|
9
|
+
"description": "Export as an OpenFOAM preCICE Adapter Configuration."
|
|
10
|
+
},
|
|
11
|
+
"ISSM": {
|
|
12
|
+
"url": "https://github.com/precice/adapter-schema/blob/main/export-formats/issm-example.yaml",
|
|
13
|
+
"description": "Export as an ISSM preCICE Adapter Configuration in YAML."
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"title": "preCICE Adapter Configuration Schema",
|
|
18
|
+
"description": "A JSON schema for configurations of adapters and tools within the preCICE ecosystem. Use the schema for validation and LLM-based auto-conversion to other configuration languages (e.g., OpenFOAM dictionary or YAML). The schema is developed as part of the preECO standardization, see https://precice.discourse.group/t/shape-the-future-of-the-precice-ecosystem-the-preeco-project/2019.",
|
|
19
|
+
"properties": {
|
|
20
|
+
"participant_name": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Name of the participant.",
|
|
23
|
+
"default": "Fluid",
|
|
24
|
+
"examples": [
|
|
25
|
+
"Fluid",
|
|
26
|
+
"Solid",
|
|
27
|
+
"Fluid-Left"
|
|
28
|
+
],
|
|
29
|
+
"minLength": 1,
|
|
30
|
+
"pattern": "^[A-Z][a-zA-Z0-9-]*$"
|
|
31
|
+
},
|
|
32
|
+
"precice_config_file_path": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Path to the preCICE configuration file relative to the current working directory of the coupled solver.",
|
|
35
|
+
"default": "../precice-config.xml",
|
|
36
|
+
"minLength": 1,
|
|
37
|
+
"pattern": "^/?(?:\\.\\./)*([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*/)*[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\\.xml$"
|
|
38
|
+
},
|
|
39
|
+
"interfaces": {
|
|
40
|
+
"type": "array",
|
|
41
|
+
"items": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"properties": {
|
|
44
|
+
"mesh_name": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"description": "Name of the mesh associated with this interface.",
|
|
47
|
+
"default": "Fluid-Mesh",
|
|
48
|
+
"examples": [
|
|
49
|
+
"Fluid-Mesh",
|
|
50
|
+
"Solid-Mesh",
|
|
51
|
+
"Fluid-Upstream-Mesh",
|
|
52
|
+
"Fluid-Upstream-Mesh-Centers",
|
|
53
|
+
"Fluid-Upstream-Mesh-Nodes"
|
|
54
|
+
],
|
|
55
|
+
"minLength": 6,
|
|
56
|
+
"pattern": "^[A-Z][a-zA-Z0-9]*(?:-[A-Z][a-zA-Z0-9]*)*-Mesh(?:-[A-Z][a-zA-Z0-9]*)*$"
|
|
57
|
+
},
|
|
58
|
+
"patches": {
|
|
59
|
+
"type": "array",
|
|
60
|
+
"description": "List of mesh or geometry patches (boundary or volume) to locate the interface.",
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"minLength": 1
|
|
64
|
+
},
|
|
65
|
+
"minItems": 1
|
|
66
|
+
},
|
|
67
|
+
"location": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "Further specification of mesh locations",
|
|
70
|
+
"minLength": 1,
|
|
71
|
+
"examples": [
|
|
72
|
+
"faceCenters",
|
|
73
|
+
"volumeCenters",
|
|
74
|
+
"faceNodes",
|
|
75
|
+
"nodes"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"write_data": {
|
|
79
|
+
"type": "array",
|
|
80
|
+
"description": "List of data fields to be written to this mesh.",
|
|
81
|
+
"items": {
|
|
82
|
+
"$ref": "#/$defs/precice_data"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"read_data": {
|
|
86
|
+
"type": "array",
|
|
87
|
+
"description": "List of data fields to be read from this mesh.",
|
|
88
|
+
"items": {
|
|
89
|
+
"$ref": "#/$defs/precice_data"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"is_received": {
|
|
93
|
+
"type": "boolean",
|
|
94
|
+
"description": "Whether mesh is received from another participant for (direct) API access or not (i.e. provided)."
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"required": [
|
|
98
|
+
"mesh_name"
|
|
99
|
+
],
|
|
100
|
+
"if": {
|
|
101
|
+
"properties": {
|
|
102
|
+
"is_received": {
|
|
103
|
+
"const": true
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"then": {
|
|
108
|
+
"not": {
|
|
109
|
+
"required": [
|
|
110
|
+
"location"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"minItems": 1
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"required": [
|
|
119
|
+
"participant_name",
|
|
120
|
+
"precice_config_file_path",
|
|
121
|
+
"interfaces"
|
|
122
|
+
],
|
|
123
|
+
"additionalProperties": {
|
|
124
|
+
"title": "Solver settings",
|
|
125
|
+
"description": "Optional solver specific settings. We recommend calling the main object after the solver, e.g. 'mbdyn'",
|
|
126
|
+
"type": "object",
|
|
127
|
+
"examples": [
|
|
128
|
+
"mbdyn",
|
|
129
|
+
"issm",
|
|
130
|
+
"code_aster",
|
|
131
|
+
"tau"
|
|
132
|
+
],
|
|
133
|
+
"additionalProperties": {
|
|
134
|
+
"title": "Solver parameter",
|
|
135
|
+
"oneOf": [
|
|
136
|
+
{
|
|
137
|
+
"title": "String property",
|
|
138
|
+
"description": "An optional string setting, such as the location of the solver configuration file.",
|
|
139
|
+
"type": "string",
|
|
140
|
+
"examples": [
|
|
141
|
+
"root_path",
|
|
142
|
+
"model_name",
|
|
143
|
+
"input_file_path",
|
|
144
|
+
"output_file_path"
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"title": "Number property",
|
|
149
|
+
"description": "An optional number setting, such as the write interval of the solver.",
|
|
150
|
+
"type": "number",
|
|
151
|
+
"examples": [
|
|
152
|
+
"write-interval",
|
|
153
|
+
"delay"
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"$defs": {
|
|
160
|
+
"precice_data": {
|
|
161
|
+
"type": "object",
|
|
162
|
+
"properties": {
|
|
163
|
+
"name": {
|
|
164
|
+
"type": "string",
|
|
165
|
+
"description": "Name of the data as specified in the preCICE configuration.",
|
|
166
|
+
"default": "Force",
|
|
167
|
+
"examples": [
|
|
168
|
+
"Force",
|
|
169
|
+
"Displacement",
|
|
170
|
+
"Velocity",
|
|
171
|
+
"Temperature",
|
|
172
|
+
"Heat-Flux",
|
|
173
|
+
"Force1",
|
|
174
|
+
"Force-Left",
|
|
175
|
+
"Heat-Transfer-Coefficient",
|
|
176
|
+
"Sink-Temperature"
|
|
177
|
+
],
|
|
178
|
+
"minLength": 1,
|
|
179
|
+
"pattern": "^[A-Z][a-zA-Z0-9]*(?:-[A-Za-z0-9]+)*$"
|
|
180
|
+
},
|
|
181
|
+
"solver_name": {
|
|
182
|
+
"type": "string",
|
|
183
|
+
"description": "Name of the data as used by the solver (optional).",
|
|
184
|
+
"examples": [
|
|
185
|
+
"temp",
|
|
186
|
+
"T"
|
|
187
|
+
],
|
|
188
|
+
"minLength": 1
|
|
189
|
+
},
|
|
190
|
+
"operation": {
|
|
191
|
+
"type": "string",
|
|
192
|
+
"description": "Operation applied by the adapter on the data (optional).",
|
|
193
|
+
"examples": [
|
|
194
|
+
"value",
|
|
195
|
+
"gradient"
|
|
196
|
+
],
|
|
197
|
+
"minLength": 1
|
|
198
|
+
},
|
|
199
|
+
"flip-normal": {
|
|
200
|
+
"type": "boolean",
|
|
201
|
+
"title": "Use a non-standard assumption for the direction of fluxes.",
|
|
202
|
+
"description": "Flip the direction of the normal vector for flux-type fields. Default assumption: written fields face outwards, read fields face inwards.",
|
|
203
|
+
"default": false
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"required": [
|
|
207
|
+
"name"
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
preCICE Adapter Schema Validation Package
|
|
3
|
+
|
|
4
|
+
This package provides validation functionality for preCICE adapter configurations.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import jsonschema
|
|
9
|
+
from functools import cache
|
|
10
|
+
from importlib.resources import files
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@cache
|
|
14
|
+
def _load_schema():
|
|
15
|
+
"""Load and cache the JSON schema."""
|
|
16
|
+
schema_text = files("preciceadapterschema").joinpath("precice_adapter_config.schema.json").read_text()
|
|
17
|
+
return json.loads(schema_text)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def validate(instance):
|
|
21
|
+
"""
|
|
22
|
+
Validate instance data against the preCICE adapter configuration schema.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
instance: The configuration data to validate (dict or JSON-compatible object)
|
|
26
|
+
|
|
27
|
+
Raises:
|
|
28
|
+
jsonschema.exceptions.ValidationError: If the instance is invalid
|
|
29
|
+
jsonschema.exceptions.SchemaError: If the schema itself is invalid
|
|
30
|
+
"""
|
|
31
|
+
schema = _load_schema()
|
|
32
|
+
jsonschema.validate(instance=instance, schema=schema)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
__all__ = ['validate']
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "precice-adapter-schema"
|
|
7
|
+
version = "v0.4.1"
|
|
8
|
+
description = "Validation utility for preCICE adapter configurations"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "preCICE developers", email = "info@precice.org"}
|
|
13
|
+
]
|
|
14
|
+
keywords = ["preCICE", "adapter", "validation", "schema"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"jsonschema>=4.0.0",
|
|
24
|
+
"importlib-resources>=5.0.0; python_version < '3.9'",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/precice/adapter-schema"
|
|
29
|
+
Repository = "https://github.com/precice/adapter-schema"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
packages = ["preciceadapterschema"]
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.package-data]
|
|
35
|
+
preciceadapterschema = ["*.json"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools-git-versioning]
|
|
38
|
+
enabled = true
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the preciceadapterschema package.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import unittest
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
from importlib.resources import files
|
|
11
|
+
except ImportError:
|
|
12
|
+
from importlib_resources import files
|
|
13
|
+
|
|
14
|
+
import preciceadapterschema
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestValidateFunction(unittest.TestCase):
|
|
18
|
+
"""Tests for the validate function."""
|
|
19
|
+
|
|
20
|
+
def test_schema_file_accessible_via_importlib(self):
|
|
21
|
+
"""Test that the schema file is accessible via importlib.resources."""
|
|
22
|
+
try:
|
|
23
|
+
schema_text = files("preciceadapterschema").joinpath("precice_adapter_config.schema.json").read_text()
|
|
24
|
+
schema = json.loads(schema_text)
|
|
25
|
+
self.assertIsInstance(schema, dict, "Schema should be a dictionary")
|
|
26
|
+
except Exception as e:
|
|
27
|
+
self.fail(f"Failed to load schema via importlib.resources: {e}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_schema_for_valid_config(self):
|
|
31
|
+
"""Test that the validation function succeeds for a valid config."""
|
|
32
|
+
valid_config_path = os.path.join(os.path.dirname(__file__), "configs", "valid_config.json")
|
|
33
|
+
with open(valid_config_path, "r") as f:
|
|
34
|
+
valid_config = json.load(f)
|
|
35
|
+
try:
|
|
36
|
+
preciceadapterschema.validate(valid_config)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
self.fail(f"Validation failed for valid config: {e}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_schema_for_empty_config(self):
|
|
43
|
+
"""Test that the validation function fails for an empty config.
|
|
44
|
+
As the schema requires certain fields, an empty config is invalid and should raise an exception."""
|
|
45
|
+
empty_config_path = os.path.join(os.path.dirname(__file__), "configs", "empty_config.json")
|
|
46
|
+
with open(empty_config_path, "r") as f:
|
|
47
|
+
empty_config = json.load(f)
|
|
48
|
+
try:
|
|
49
|
+
preciceadapterschema.validate(empty_config)
|
|
50
|
+
# If we reach this point, the validation did not raise an exception as expected
|
|
51
|
+
self.fail("Validation did not fail for empty config as expected")
|
|
52
|
+
except Exception as e:
|
|
53
|
+
# We expect an exception, so this is a success case
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_schema_for_invalid_config(self):
|
|
58
|
+
"""Test that the validation function fails for a invalid config."""
|
|
59
|
+
invalid_config_path = os.path.join(os.path.dirname(__file__), "configs", "invalid_config.json")
|
|
60
|
+
with open(invalid_config_path, "r") as f:
|
|
61
|
+
invalid_config = json.load(f)
|
|
62
|
+
try:
|
|
63
|
+
preciceadapterschema.validate(invalid_config)
|
|
64
|
+
# If we reach this point, the validation did not raise an exception as expected
|
|
65
|
+
self.fail("Validation did not fail for invalid config as expected")
|
|
66
|
+
except Exception as e:
|
|
67
|
+
# We expect an exception, so this is a success case
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == '__main__':
|
|
74
|
+
unittest.main()
|