import os def generate_python_sources(): sources = {} for file in sorted(os.listdir("python")): if not file.endswith(".py"): continue key = file.split(".")[0] with open("python/" + file) as f: value = f.read() const_array = ','.join([str(b) for b in value.encode('utf-8')]) sources[key] = '(const char[]){' + const_array + '}' header = '''#pragma once // generated by prebuild.py #include #include namespace pkpy{ inline const std::map kPythonLibs = { ''' for key, value in sources.items(): header += f' {{ "{key}", {value} }},\n' header += ''' }; } // namespace pkpy ''' return header # use LF line endings instead of CRLF with open("include/pocketpy/_generated.h", "wt", encoding='utf-8', newline='\n') as f: f.write(generate_python_sources())