1
0

compileall.py 972 B

123456789101112131415161718192021222324252627282930313233343536
  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. assert os.path.isfile(src_path)
  11. cmd = f'{pkpy_exe} --compile "{src_path}" "{dst_path}"'
  12. if os.system(cmd) != 0:
  13. print(src_path)
  14. exit(1)
  15. if os.path.isfile(source_dir):
  16. if output_dir.endswith('.py'):
  17. output_dir += 'c'
  18. do_compile(source_dir, output_dir)
  19. exit(0)
  20. for root, _, files in os.walk(source_dir):
  21. for file in files:
  22. if not file.endswith('.py'):
  23. continue
  24. src_path = os.path.join(root, file)
  25. dst_path = os.path.join(
  26. output_dir,
  27. os.path.relpath(root, source_dir),
  28. file + 'c'
  29. )
  30. os.makedirs(os.path.dirname(dst_path), exist_ok=True)
  31. do_compile(src_path, dst_path)