| 123456789101112131415161718192021222324252627282930313233 |
- 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 <map>
- #include <string>
- namespace pkpy{
- inline const std::map<std::string, const char*> 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())
|