MCPcopy Create free account
hub / github.com/JDAI-CV/DNNLibrary / update_code

Function update_code

generate_code.py:192–211  ·  view source on GitHub ↗

replace the text surrounded by "label start" and "label end" to new_code :param file: the .cpp or .h file :param label: the label surrounds the text to be replaced

(file: str, label: str, reformat: bool=True)

Source from the content-addressed store, hash-verified

190
191
192def update_code(file: str, label: str, reformat: bool=True) -> None:
193 """
194 replace the text surrounded by "label start" and "label end" to new_code
195 :param file: the .cpp or .h file
196 :param label: the label surrounds the text to be replaced
197 """
198 global str_io
199 with open(file, 'r') as f:
200 s = f.read()
201 start = '// {} start\n'.format(label)
202 idx1 = s.find(start) + len(start)
203 end = '// {} end'.format(label)
204 idx2 = s.find(end)
205 assert start in s and end in s
206 with open(file, 'w') as f:
207 new_s = s[:idx1] + str_io.getvalue() + s[idx2:]
208 f.write(new_s)
209 str_io = io.StringIO()
210 if reformat:
211 clang_format(file)
212
213
214def generate_onnx_converter():

Callers 4

generate_onnx_converterFunction · 0.85
generate_daq_readerFunction · 0.85
generate_fbsFunction · 0.85
generate_model_builderFunction · 0.85

Calls 1

clang_formatFunction · 0.85

Tested by

no test coverage detected