build-wheel-macos.sh 3.6 KB

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