25
25
# exactly that meta-model version.
26
26
import aas_core_meta .v3
27
27
28
+ import aas_core_codegen .jsonschema .main
29
+ import aas_core_codegen .run
30
+ import aas_core_codegen .specific_implementations
31
+ import aas_core_codegen .common
32
+
28
33
AAS_CORE_META_DEPENDENCY_RE = re .compile (
29
34
r"aas-core-meta@git\+https://github.com/aas-core-works/aas-core-meta@([a-fA-F0-9]+)#egg=aas-core-meta"
30
35
)
35
40
36
41
37
42
def _make_sure_no_changed_files (
38
- repo_dir : pathlib .Path , expected_branch : str
43
+ repo_dir : pathlib .Path , expected_branch : str
39
44
) -> Optional [int ]:
40
45
"""
41
46
Make sure that no files are modified in the given repository.
@@ -63,8 +68,7 @@ def _make_sure_no_changed_files(
63
68
64
69
65
70
def _update_setup_py (
66
- our_repo : pathlib .Path , aas_core_meta_revision : str ,
67
- aas_core_codegen_revision : str
71
+ our_repo : pathlib .Path , aas_core_meta_revision : str , aas_core_codegen_revision : str
68
72
) -> None :
69
73
"""Update the aas-core-meta in setup.py."""
70
74
setup_py = our_repo / "setup.py"
@@ -88,7 +92,7 @@ def _update_setup_py(
88
92
89
93
90
94
def _uninstall_and_install_aas_core_meta (
91
- our_repo : pathlib .Path , aas_core_meta_revision : str
95
+ our_repo : pathlib .Path , aas_core_meta_revision : str
92
96
) -> None :
93
97
"""Uninstall and install the latest aas-core-meta in the virtual environment."""
94
98
subprocess .check_call (
@@ -108,7 +112,7 @@ def _uninstall_and_install_aas_core_meta(
108
112
109
113
110
114
def _uninstall_and_install_aas_core_codegen (
111
- our_repo : pathlib .Path , aas_core_codegen_revision : str
115
+ our_repo : pathlib .Path , aas_core_codegen_revision : str
112
116
) -> None :
113
117
"""Uninstall and install the latest aas-core-codegen in the virtual environment."""
114
118
subprocess .check_call (
@@ -127,15 +131,15 @@ def _uninstall_and_install_aas_core_codegen(
127
131
)
128
132
129
133
130
- def _copy_python_sdk_and_schemas_from_aas_core_codegen (
131
- aas_core_codegen_repo : pathlib .Path ,
132
- our_repo : pathlib .Path ,
133
- aas_core_codegen_revision : str ,
134
+ def _copy_python_sdk_and_xml_schema_from_aas_core_codegen (
135
+ aas_core_codegen_repo : pathlib .Path ,
136
+ our_repo : pathlib .Path ,
137
+ aas_core_codegen_revision : str ,
134
138
) -> None :
135
139
"""Copy the generated Python SDK from aas-core-codegen's test data."""
136
140
source_dir = (
137
- aas_core_codegen_repo
138
- / "test_data/python/test_main/aas_core_meta.v3/expected_output"
141
+ aas_core_codegen_repo
142
+ / "test_data/python/test_main/aas_core_meta.v3/expected_output"
139
143
)
140
144
141
145
target_dir = our_repo / "aas_core3"
@@ -157,22 +161,63 @@ def _copy_python_sdk_and_schemas_from_aas_core_codegen(
157
161
'''
158
162
init_py .write_text (text , encoding = "utf-8" )
159
163
160
- shutil .copy (
161
- aas_core_codegen_repo
162
- / "test_data/jsonschema/test_main/aas_core_meta.v3/expected_output/schema.json" ,
163
- our_repo / "test_data/schema.json" ,
164
- )
165
-
166
164
shutil .copy (
167
165
aas_core_codegen_repo
168
166
/ "test_data/xsd/test_main/aas_core_meta.v3/expected_output/schema.xsd" ,
169
167
our_repo / "test_data/schema.xsd" ,
170
168
)
171
169
172
170
171
+ def _generate_jsonschema_for_python (
172
+ our_repo : pathlib .Path ,
173
+ ) -> None :
174
+ model_path = pathlib .Path (aas_core_meta .v3 .__file__ )
175
+ symbol_table_atok , error = aas_core_codegen .run .load_model (model_path = model_path )
176
+ assert error is None , f"Unexpected error loading { model_path } : { error } "
177
+ assert symbol_table_atok is not None
178
+
179
+ symbol_table , _ = symbol_table_atok
180
+
181
+ text , errors = aas_core_codegen .jsonschema .main .generate (
182
+ symbol_table = symbol_table ,
183
+ spec_impls = {
184
+ aas_core_codegen .specific_implementations .ImplementationKey (
185
+ "schema_base.json"
186
+ ): aas_core_codegen .common .Stripped (
187
+ """\
188
+ {
189
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
190
+ "title": "AssetAdministrationShellEnvironment",
191
+ "type": "object",
192
+ "allOf": [
193
+ {
194
+ "$ref": "#/definitions/Environment"
195
+ }
196
+ ]
197
+ }"""
198
+ )
199
+ },
200
+ # NOTE (mristin):
201
+ # We rely that the aas-core-meta uses Python-conform regular expressions,
202
+ # which jsonschema library can readily use as well.
203
+ fix_pattern = lambda pattern : pattern ,
204
+ )
205
+
206
+ if errors is not None :
207
+ errors_joined = "\n \n " .join (error .message for error in errors )
208
+ raise AssertionError (
209
+ f"Unexpected errors when generating the Python-conform JSON schema:\n "
210
+ f"{ errors_joined } "
211
+ )
212
+
213
+ assert text is not None
214
+
215
+ (our_repo / "test_data/schema.json" ).write_text (text , encoding = "utf-8" )
216
+
217
+
173
218
def _run_in_parallel (
174
- calls : Sequence [Callable [[], subprocess .Popen [AnyStr ]]],
175
- on_status_update : Callable [[int ], None ],
219
+ calls : Sequence [Callable [[], subprocess .Popen [AnyStr ]]],
220
+ on_status_update : Callable [[int ], None ],
176
221
) -> Optional [int ]:
177
222
"""
178
223
Run the given scripts in parallel.
@@ -301,9 +346,9 @@ def _run_tests_in_parallel(our_repo: pathlib.Path) -> Optional[int]:
301
346
f"tests.{ pth .stem } "
302
347
for pth in (our_repo / "tests" ).glob ("test_*.py" )
303
348
if (
304
- pth .is_file ()
305
- and not pth .name .startswith ("__" )
306
- and not pth .name .startswith ("." )
349
+ pth .is_file ()
350
+ and not pth .name .startswith ("__" )
351
+ and not pth .name .startswith ("." )
307
352
)
308
353
]
309
354
@@ -367,23 +412,18 @@ def _generate_test_data(our_repo: pathlib.Path) -> Optional[int]:
367
412
for name in ("generate_json.py" , "generate_rdf.py" , "generate_xml.py" )
368
413
]
369
414
370
- # pylint: disable=consider-using-with
371
- commands = [
372
- [
415
+ start = time .perf_counter ()
416
+
417
+ for script in scripts :
418
+ command = [
373
419
sys .executable ,
374
420
str (script ),
375
421
"--model_path" ,
376
422
aas_core_meta .v3 .__file__ ,
377
423
"--test_data_dir" ,
378
- test_data_dir ,
424
+ str ( test_data_dir ) ,
379
425
]
380
- for script in scripts
381
- ]
382
- # pylint: enable=consider-using-with
383
426
384
- start = time .perf_counter ()
385
-
386
- for command in commands :
387
427
command_escaped = " " .join (shlex .quote (part ) for part in command )
388
428
print (f"Running: { command_escaped } " )
389
429
subprocess .check_call (command , cwd = str (our_repo ))
@@ -395,8 +435,7 @@ def _generate_test_data(our_repo: pathlib.Path) -> Optional[int]:
395
435
396
436
397
437
def _create_branch_commit_and_push (
398
- our_repo : pathlib .Path , aas_core_meta_revision : str ,
399
- aas_core_codegen_revision : str
438
+ our_repo : pathlib .Path , aas_core_meta_revision : str , aas_core_codegen_revision : str
400
439
) -> None :
401
440
"""Create a feature branch, commit the changes and push it."""
402
441
branch = (
@@ -593,7 +632,9 @@ def main() -> int:
593
632
our_repo = our_repo , aas_core_codegen_revision = aas_core_codegen_revision
594
633
)
595
634
596
- _copy_python_sdk_and_schemas_from_aas_core_codegen (
635
+ _generate_jsonschema_for_python (our_repo = our_repo )
636
+
637
+ _copy_python_sdk_and_xml_schema_from_aas_core_codegen (
597
638
aas_core_codegen_repo = aas_core_codegen_repo ,
598
639
our_repo = our_repo ,
599
640
aas_core_codegen_revision = aas_core_codegen_revision ,
0 commit comments