build_exo.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import site
  2. import subprocess
  3. import sys
  4. import os
  5. import pkgutil
  6. import shutil
  7. def run():
  8. site_packages = site.getsitepackages()[0]
  9. command = [
  10. f"{sys.executable}", "-m", "nuitka", "exo/main.py",
  11. "--company-name=exolabs",
  12. "--product-name=exo",
  13. "--output-dir=dist",
  14. "--follow-imports",
  15. "--standalone",
  16. "--output-filename=exo",
  17. "--python-flag=no_site",
  18. "--onefile"
  19. ]
  20. if sys.platform == "darwin":
  21. command.extend([
  22. "--macos-app-name=exo",
  23. "--macos-app-mode=gui",
  24. "--macos-app-version=0.0.1",
  25. "--macos-signed-app-name=com.exolabs.exo",
  26. "--include-distribution-meta=mlx",
  27. "--include-module=mlx._reprlib_fix",
  28. "--include-module=mlx._os_warning",
  29. f"--include-data-files={site_packages}/mlx/lib/mlx.metallib=mlx/lib/mlx.metallib",
  30. f"--include-data-files={site_packages}/mlx/lib/mlx.metallib=./mlx.metallib",
  31. "--include-distribution-meta=pygments",
  32. "--nofollow-import-to=tinygrad"
  33. ])
  34. inference_modules = [
  35. name for _, name, _ in pkgutil.iter_modules(['exo/inference/mlx/models'])
  36. ]
  37. for module in inference_modules:
  38. command.append(f"--include-module=exo.inference.mlx.models.{module}")
  39. elif sys.platform == "win32":
  40. command.extend([
  41. "--windows-icon-from-ico=docs/exo-logo-win.ico",
  42. "--file-version=0.0.1",
  43. "--product-version=0.0.1"
  44. ])
  45. elif sys.platform.startswith("linux"):
  46. command.extend([
  47. "--include-distribution-metadata=pygments",
  48. "--linux-icon=docs/exo-rounded.png"
  49. ])
  50. try:
  51. subprocess.run(command, check=True)
  52. print("Build completed!")
  53. os.makedirs('./dist/main.dist/transformers/models', exist_ok=True)
  54. shutil.copytree(f"{site_packages}/transformers/models", "dist/main.dist/transformers/models", dirs_exist_ok=True)
  55. except subprocess.CalledProcessError as e:
  56. print(f"An error occurred: {e}")
  57. if __name__ == "__main__":
  58. run()