build-wheel-macos.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # Cause the script to exit if a single command fails.
  3. set -e
  4. # Show explicitly which commands are currently running.
  5. set -x
  6. DOWNLOAD_DIR=python_downloads
  7. NODE_VERSION="14"
  8. PY_MMS=("3.9" "3.10" "3.11" "3.12")
  9. if [[ -n "${SKIP_DEP_RES}" ]]; then
  10. ./ci/env/install-bazel.sh
  11. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  12. if [ "$(uname -m)" = "arm64" ]; then
  13. curl -o- https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh | bash
  14. else
  15. curl -o- https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh | bash
  16. fi
  17. conda init bash
  18. source ~/.bash_profile
  19. # Use the latest version of Node.js in order to build the dashboard.
  20. source "$HOME"/.nvm/nvm.sh
  21. nvm install $NODE_VERSION
  22. nvm use $NODE_VERSION
  23. fi
  24. # Build the dashboard so its static assets can be included in the wheel.
  25. pushd python/ray/dashboard/client
  26. source "$HOME"/.nvm/nvm.sh
  27. npm ci
  28. npm run build
  29. popd
  30. mkdir -p .whl
  31. for ((i=0; i<${#PY_MMS[@]}; ++i)); do
  32. PY_MM=${PY_MMS[i]}
  33. CONDA_ENV_NAME="p$PY_MM"
  34. # The -f flag is passed twice to also run git clean in the arrow subdirectory.
  35. # The -d flag removes directories. The -x flag ignores the .gitignore file,
  36. # and the -e flag ensures that we don't remove the .whl directory.
  37. git clean -f -f -x -d -e .whl -e $DOWNLOAD_DIR -e python/ray/dashboard/client -e dashboard/client
  38. # Install python using conda. This should be easier to produce consistent results in buildkite and locally.
  39. [ ! -f "$HOME/.bash_profile" ] && conda init bash
  40. source ~/.bash_profile
  41. conda create -y -n "$CONDA_ENV_NAME"
  42. conda activate "$CONDA_ENV_NAME"
  43. conda remove -y python || true
  44. conda install -y python="$PY_MM"
  45. # NOTE: We expect conda to set the PATH properly.
  46. PIP_CMD=pip
  47. PYTHON_EXE=python
  48. $PIP_CMD install --upgrade pip
  49. if [ -z "${TRAVIS_COMMIT}" ]; then
  50. TRAVIS_COMMIT=${BUILDKITE_COMMIT}
  51. fi
  52. pushd python
  53. # Setuptools on CentOS is too old to install arrow 0.9.0, therefore we upgrade.
  54. # TODO: Unpin after https://github.com/pypa/setuptools/issues/2849 is fixed.
  55. $PIP_CMD install --upgrade setuptools==69.5.1
  56. $PIP_CMD install -q cython==0.29.37
  57. # Install wheel to avoid the error "invalid command 'bdist_wheel'".
  58. $PIP_CMD install -q wheel
  59. # Set the commit SHA in _version.py.
  60. if [ -n "$TRAVIS_COMMIT" ]; then
  61. echo "TRAVIS_COMMIT variable detected. ray.__commit__ will be set to $TRAVIS_COMMIT"
  62. else
  63. echo "TRAVIS_COMMIT variable is not set, getting the current commit from git."
  64. TRAVIS_COMMIT=$(git rev-parse HEAD)
  65. fi
  66. sed -i .bak "s/{{RAY_COMMIT_SHA}}/$TRAVIS_COMMIT/g" ray/_version.py && rm ray/_version.py.bak
  67. # Add the correct Python to the path and build the wheel. This is only
  68. # needed so that the installation finds the cython executable.
  69. # build ray wheel
  70. $PYTHON_EXE setup.py bdist_wheel
  71. # build ray-cpp wheel
  72. RAY_INSTALL_CPP=1 $PYTHON_EXE setup.py bdist_wheel
  73. mv dist/*.whl ../.whl/
  74. popd
  75. # cleanup
  76. conda deactivate
  77. conda env remove -y -n "$CONDA_ENV_NAME"
  78. done