compileall.py 775 B

12345678910111213141516171819202122232425262728
  1. import sys
  2. import os
  3. if len(sys.argv) != 4:
  4. print('Usage: python compileall.py <pocketpy_executable> <source_dir> <output_dir>')
  5. exit(1)
  6. pkpy_exe = sys.argv[1]
  7. source_dir = sys.argv[2]
  8. output_dir = sys.argv[3]
  9. def do_compile(src_path, dst_path):
  10. cmd = f'{pkpy_exe} --compile "{src_path}" "{dst_path}"'
  11. print(src_path)
  12. assert os.system(cmd) == 0
  13. for root, _, files in os.walk(source_dir):
  14. for file in files:
  15. if not file.endswith('.py'):
  16. continue
  17. src_path = os.path.join(root, file)
  18. dst_path = os.path.join(
  19. output_dir,
  20. os.path.relpath(root, source_dir),
  21. file + 'c'
  22. )
  23. os.makedirs(os.path.dirname(dst_path), exist_ok=True)
  24. do_compile(src_path, dst_path)