build-wheel-macos.sh 3.8 KB

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