22from __future__ import annotations
33
44import ast
5- import contextlib
65import json
76import re
87import subprocess
98import sys
10- import tempfile
119import textwrap
1210from collections .abc import Callable
1311from dataclasses import dataclass
1412from pathlib import Path
1513
1614ROOT = Path (__file__ ).resolve ().parents [1 ]
17- if str (ROOT ) not in sys .path :
18- sys .path .append (str (ROOT ))
19-
20- from scripts .schema_patches import apply_schema_patches # noqa: E402
21-
2215SCHEMA_DIR = ROOT / "schema"
2316SCHEMA_JSON = SCHEMA_DIR / "schema.json"
2417VERSION_FILE = SCHEMA_DIR / "VERSION"
@@ -143,23 +136,12 @@ def generate_schema() -> None:
143136 )
144137 sys .exit (1 )
145138
146- schema_payload = json .loads (SCHEMA_JSON .read_text (encoding = "utf-8" ))
147- schema_payload , patch_warnings = apply_schema_patches (schema_payload )
148- for warning in patch_warnings :
149- print (f"Warning: { warning .message } " , file = sys .stderr )
150-
151- patched_schema_path : Path | None = None
152- with tempfile .NamedTemporaryFile ("w" , suffix = ".json" , delete = False , encoding = "utf-8" ) as handle :
153- json .dump (schema_payload , handle , indent = 2 )
154- handle .write ("\n " )
155- patched_schema_path = Path (handle .name )
156-
157139 cmd = [
158140 sys .executable ,
159141 "-m" ,
160142 "datamodel_code_generator" ,
161143 "--input" ,
162- str (patched_schema_path ),
144+ str (SCHEMA_JSON ),
163145 "--input-file-type" ,
164146 "jsonschema" ,
165147 "--output" ,
@@ -173,15 +155,10 @@ def generate_schema() -> None:
173155 "--snake-case-field" ,
174156 ]
175157
176- try :
177- subprocess .check_call (cmd ) # noqa: S603
178- warnings = postprocess_generated_schema (SCHEMA_OUT )
179- for warning in warnings :
180- print (f"Warning: { warning } " , file = sys .stderr )
181- finally :
182- if patched_schema_path is not None :
183- with contextlib .suppress (OSError ):
184- patched_schema_path .unlink ()
158+ subprocess .check_call (cmd ) # noqa: S603
159+ warnings = postprocess_generated_schema (SCHEMA_OUT )
160+ for warning in warnings :
161+ print (f"Warning: { warning } " , file = sys .stderr )
185162
186163
187164def postprocess_generated_schema (output_path : Path ) -> list [str ]:
0 commit comments