MCPcopy Index your code
hub / github.com/SFTtech/openage / postprocess_write

Function postprocess_write

openage/codegen/codegen.py:258–288  ·  view source on GitHub ↗

Post-processes a single write operation, as intercepted during codegen.

(parts, data: str)

Source from the content-addressed store, hash-verified

256
257
258def postprocess_write(parts, data: str) -> str:
259 """
260 Post-processes a single write operation, as intercepted during codegen.
261 """
262 # test whether filename starts with 'libopenage/'
263 if parts[0] != b"libopenage":
264 raise ValueError("Not in libopenage source directory")
265
266 # test whether filename matches the pattern *.gen.*
267 name, extension = os.path.splitext(parts[-1].decode())
268 if not name.endswith('.gen'):
269 raise ValueError("Doesn't match required filename format .gen.SUFFIX")
270
271 # check file extension, and use the appropriate comment prefix
272 if extension in {'.h', '.cpp'}:
273 comment_prefix = '//'
274 else:
275 raise ValueError("Extension not in {.h, .cpp}")
276
277 datalines = data.decode('ascii').split('\n')
278 if 'Copyright' in datalines[0]:
279 datalines = datalines[1:]
280
281 headerlines = []
282 for line in get_header_lines():
283 if line:
284 headerlines.append(comment_prefix + " " + line)
285 else:
286 headerlines.append("")
287
288 return '\n'.join(chain(headerlines, datalines)).encode('ascii')

Callers 1

codegenFunction · 0.85

Calls 2

get_header_linesFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected