build-wheel-macos.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/travis/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
  35. # Build the dashboard so its static assets can be included in the wheel.
  36. # TODO(mfitton): switch this back when deleting old dashboard code.
  37. pushd python/ray/new_dashboard/client
  38. npm ci
  39. npm run build
  40. popd
  41. for ((i=0; i<${#PY_VERSIONS[@]}; ++i)); do
  42. PY_VERSION=${PY_VERSIONS[i]}
  43. PY_INST=${PY_INSTS[i]}
  44. PY_MM=${PY_MMS[i]}
  45. NUMPY_VERSION=${NUMPY_VERSIONS[i]}
  46. # The -f flag is passed twice to also run git clean in the arrow subdirectory.
  47. # The -d flag removes directories. The -x flag ignores the .gitignore file,
  48. # and the -e flag ensures that we don't remove the .whl directory.
  49. git clean -f -f -x -d -e .whl -e $DOWNLOAD_DIR -e python/ray/new_dashboard/client -e dashboard/client
  50. # Install Python.
  51. INST_PATH=python_downloads/$PY_INST
  52. curl $MACPYTHON_URL/"$PY_VERSION"/"$PY_INST" > "$INST_PATH"
  53. sudo installer -pkg "$INST_PATH" -target /
  54. PYTHON_EXE=$MACPYTHON_PY_PREFIX/$PY_MM/bin/python$PY_MM
  55. PIP_CMD="$(dirname "$PYTHON_EXE")/pip$PY_MM"
  56. pushd /tmp
  57. # Install latest version of pip to avoid brownouts.
  58. curl https://bootstrap.pypa.io/get-pip.py | $PYTHON_EXE
  59. popd
  60. pushd python
  61. # Setuptools on CentOS is too old to install arrow 0.9.0, therefore we upgrade.
  62. $PIP_CMD install --upgrade setuptools
  63. # Install setuptools_scm because otherwise when building the wheel for
  64. # Python 3.6, we see an error.
  65. $PIP_CMD install -q setuptools_scm==3.1.0
  66. # Fix the numpy version because this will be the oldest numpy version we can
  67. # support.
  68. $PIP_CMD install -q numpy=="$NUMPY_VERSION" cython==0.29.15
  69. # Install wheel to avoid the error "invalid command 'bdist_wheel'".
  70. $PIP_CMD install -q wheel
  71. # Set the commit SHA in __init__.py.
  72. if [ -n "$TRAVIS_COMMIT" ]; then
  73. sed -i.bak "s/{{RAY_COMMIT_SHA}}/$TRAVIS_COMMIT/g" ray/__init__.py && rm ray/__init__.py.bak
  74. else
  75. echo "TRAVIS_COMMIT variable not set - required to populated ray.__commit__."
  76. exit 1
  77. fi
  78. # Add the correct Python to the path and build the wheel. This is only
  79. # needed so that the installation finds the cython executable.
  80. PATH=$MACPYTHON_PY_PREFIX/$PY_MM/bin:$PATH $PYTHON_EXE setup.py bdist_wheel
  81. mv dist/*.whl ../.whl/
  82. popd
  83. done