make self_tokenize output more like a python file (#8411)

use comment for file name and join with newline instead of null byte when export to file
This commit is contained in:
chenyu
2024-12-25 14:16:30 -05:00
committed by GitHub
parent c1cd94baf6
commit 4712847766

View File

@@ -15,13 +15,13 @@ def read_code(base_path):
if 'tinygrad/runtime/autogen' in path.replace('\\', '/'): continue
fullpath = os.path.join(path, name)
code = pathlib.Path(fullpath).read_text()
ret += [(fullpath.split("tinygrad/", 1)[1], code)]
ret.append(("### " + fullpath.split("tinygrad/", 1)[1], code))
return ret
def write_code_to_file(filename, code_list):
"""Writes the combined code to a specified file."""
with open(filename, 'w') as f:
f.write('\x00'.join(flatten(code_list)))
f.write('\n'.join(flatten(code_list)))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Analyze and optionally save tinygrad code.")