Skip to content

Commit e31c7a8

Browse files
Merge pull request #8 from runtimeverification/update/format
Update ethdebug spec
2 parents a836437 + f42d5a3 commit e31c7a8

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

generate_model.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from glob import glob
22
from pathlib import Path
3+
from tempfile import NamedTemporaryFile
34

45
from datamodel_code_generator import InputFileType, generate, DataModelType
56
from datamodel_code_generator.model import PythonVersion
@@ -10,18 +11,29 @@
1011
# Ensure output directory exists
1112
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
1213

13-
generate(
14-
input_=SCHEMA_DIR,
15-
input_file_type=InputFileType.JsonSchema,
16-
output=OUTPUT_DIR,
17-
output_model_type=DataModelType.PydanticV2BaseModel,
18-
target_python_version=PythonVersion.PY_312,
19-
allow_extra_fields=False,
20-
disable_timestamp=True,
21-
reuse_model=True,
22-
use_annotated=True,
23-
field_constraints=True,
24-
custom_class_name_generator=lambda x: x.title().replace("Ethdebug/Format/", "").replace("/", "_"),
25-
use_exact_imports=True,
26-
27-
)
14+
# Temporarily rename LICENSE file so it doesn't cause parsing issues
15+
license_path = SCHEMA_DIR / "LICENSE"
16+
17+
with NamedTemporaryFile(delete=False) as tmp_file:
18+
if license_path.exists():
19+
license_path.rename(tmp_file.name)
20+
temp_license_path = Path(tmp_file.name)
21+
try:
22+
generate(
23+
input_=SCHEMA_DIR,
24+
input_file_type=InputFileType.JsonSchema,
25+
output=OUTPUT_DIR,
26+
output_model_type=DataModelType.PydanticV2BaseModel,
27+
target_python_version=PythonVersion.PY_312,
28+
allow_extra_fields=False,
29+
disable_timestamp=True,
30+
reuse_model=True,
31+
use_annotated=True,
32+
field_constraints=True,
33+
custom_class_name_generator=lambda x: x.title().replace("Ethdebug/Format/", "").replace("/", "_"),
34+
use_exact_imports=True
35+
)
36+
finally:
37+
# Restore LICENSE file
38+
if temp_license_path.exists():
39+
temp_license_path.rename(license_path)

0 commit comments

Comments
 (0)