build-wheel-macos.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # Much of this is taken from https://github.com/matthew-brett/multibuild.
  7. # This script uses "sudo", so you may need to type in a password a couple times.
  8. MACPYTHON_URL=https://www.python.org/ftp/python
  9. MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
  10. DOWNLOAD_DIR=python_downloads
  11. NODE_VERSION="14"
  12. PY_VERSIONS=("3.7.0"
  13. "3.8.2"
  14. "3.9.1"
  15. "3.10.4"
  16. )
  17. PY_INSTS=("python-3.7.0-macosx10.6.pkg"
  18. "python-3.8.2-macosx10.9.pkg"
  19. "python-3.9.1-macosx10.9.pkg"
  20. "python-3.10.4-macos11.pkg"
  21. )
  22. PY_MMS=("3.7"
  23. "3.8"
  24. "3.9"
  25. "3.10"
  26. )
  27. NUMPY_VERSIONS=("1.14.5"
  28. "1.14.5"
  29. "1.19.3"
  30. "1.22.0"
  31. )
  32. ./ci/env/install-bazel.sh
  33. mkdir -p $DOWNLOAD_DIR
  34. mkdir -p .whl
  35. # Use the latest version of Node.js in order to build the dashboard.
  36. source "$HOME"/.nvm/nvm.sh
  37. nvm install $NODE_VERSION
  38. nvm use $NODE_VERSION
  39. # Build the dashboard so its static assets can be included in the wheel.
  40. pushd python/ray/dashboard/client
  41. npm ci
  42. npm run build
  43. popd
  44. for ((i=0; i<${#PY_VERSIONS[@]}; ++i)); do
  45. PY_VERSION=${PY_VERSIONS[i]}
  46. PY_INST=${PY_INSTS[i]}
  47. PY_MM=${PY_MMS[i]}
  48. NUMPY_VERSION=${NUMPY_VERSIONS[i]}
  49. # The -f flag is passed twice to also run git clean in the arrow subdirectory.
  50. # The -d flag removes directories. The -x flag ignores the .gitignore file,
  51. # and the -e flag ensures that we don't remove the .whl directory.
  52. git clean -f -f -x -d -e .whl -e $DOWNLOAD_DIR -e python/ray/dashboard/client -e dashboard/client
  53. # Install Python.
  54. # In Buildkite, the Python packages are installed on the machien before the build has ran.
  55. PYTHON_EXE=$MACPYTHON_PY_PREFIX/$PY_MM/bin/python$PY_MM
  56. PIP_CMD="$(dirname "$PYTHON_EXE")/pip$PY_MM"
  57. if [ -z "${BUILDKITE}" ]; then
  58. INST_PATH=python_downloads/$PY_INST
  59. curl $MACPYTHON_URL/"$PY_VERSION"/"$PY_INST" > "$INST_PATH"
  60. sudo installer -pkg "$INST_PATH" -target /
  61. installer -pkg "$INST_PATH" -target /
  62. pushd /tmp
  63. # Install latest version of pip to avoid brownouts.
  64. curl https://bootstrap.pypa.io/get-pip.py | $PYTHON_EXE
  65. popd
  66. fi
  67. if [ -z "${TRAVIS_COMMIT}" ]; then
  68. TRAVIS_COMMIT=${BUILDKITE_COMMIT}
  69. fi
  70. pushd python
  71. # Setuptools on CentOS is too old to install arrow 0.9.0, therefore we upgrade.
  72. # TODO: Unpin after https://github.com/pypa/setuptools/issues/2849 is fixed.
  73. $PIP_CMD install --upgrade setuptools==58.4
  74. # Install setuptools_scm because otherwise when building the wheel for
  75. # Python 3.6, we see an error.
  76. $PIP_CMD install -q setuptools_scm==3.1.0
  77. # Fix the numpy version because this will be the oldest numpy version we can
  78. # support.
  79. $PIP_CMD install -q numpy=="$NUMPY_VERSION" cython==0.29.32
  80. # Install wheel to avoid the error "invalid command 'bdist_wheel'".
  81. $PIP_CMD install -q wheel
  82. # Set the commit SHA in __init__.py.
  83. if [ -n "$TRAVIS_COMMIT" ]; then
  84. sed -i.bak "s/{{RAY_COMMIT_SHA}}/$TRAVIS_COMMIT/g" ray/__init__.py && rm ray/__init__.py.bak
  85. else
  86. echo "TRAVIS_COMMIT variable not set - required to populated ray.__commit__."
  87. exit 1
  88. fi
  89. # Add the correct Python to the path and build the wheel. This is only
  90. # needed so that the installation finds the cython executable.
  91. # build ray wheel
  92. PATH=$MACPYTHON_PY_PREFIX/$PY_MM/bin:$PATH $PYTHON_EXE setup.py bdist_wheel
  93. # build ray-cpp wheel
  94. RAY_INSTALL_CPP=1 PATH=$MACPYTHON_PY_PREFIX/$PY_MM/bin:$PATH $PYTHON_EXE setup.py bdist_wheel
  95. mv dist/*.whl ../.whl/
  96. popd
  97. done