11from glob import glob
22from pathlib import Path
3+ from tempfile import NamedTemporaryFile
34
45from datamodel_code_generator import InputFileType , generate , DataModelType
56from datamodel_code_generator .model import PythonVersion
1011# Ensure output directory exists
1112OUTPUT_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