test-wheels.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env 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. ROOT_DIR=$(cd "$(dirname "$0")/$(dirname "$(test -L "$0" && readlink "$0" || echo "/")")"; pwd)
  7. platform=""
  8. case "${OSTYPE}" in
  9. linux*) platform="linux";;
  10. darwin*) platform="macosx";;
  11. msys*) platform="windows";;
  12. *) echo "Unrecognized platform."; exit 1;;
  13. esac
  14. BUILD_DIR="${TRAVIS_BUILD_DIR-}"
  15. if [ -z "${BUILD_DIR}" ]; then
  16. BUILD_DIR="${GITHUB_WORKSPACE}"
  17. fi
  18. if [ -n "${BUILDKITE-}" ]; then
  19. BUILD_DIR="${ROOT_DIR}/../.."
  20. fi
  21. TEST_DIR="${BUILD_DIR}/python/ray/tests"
  22. TEST_SCRIPTS=("$TEST_DIR/test_microbenchmarks.py" "$TEST_DIR/test_basic.py")
  23. DASHBOARD_TEST_SCRIPT="${BUILD_DIR}/python/ray/tests/test_dashboard.py"
  24. function retry {
  25. local n=1
  26. local max=3
  27. while true; do
  28. if "$@"; then
  29. break
  30. fi
  31. if [ $n -lt $max ]; then
  32. ((n++))
  33. echo "Command failed. Attempt $n/$max:"
  34. else
  35. echo "The command has failed after $n attempts."
  36. exit 1
  37. fi
  38. done
  39. }
  40. if [[ "$platform" == "linux" ]]; then
  41. # Install miniconda.
  42. PY_WHEEL_VERSIONS=("36" "37" "38" "39")
  43. PY_MMS=("3.6.13"
  44. "3.7.10"
  45. "3.8.10"
  46. "3.9.5")
  47. wget --quiet "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" -O miniconda3.sh
  48. "${ROOT_DIR}"/../suppress_output bash miniconda3.sh -b -p "$HOME/miniconda3"
  49. export PATH="$HOME/miniconda3/bin:$PATH"
  50. for ((i=0; i<${#PY_MMS[@]}; ++i)); do
  51. PY_MM="${PY_MMS[i]}"
  52. PY_WHEEL_VERSION="${PY_WHEEL_VERSIONS[i]}"
  53. conda install -y python="${PY_MM}"
  54. PYTHON_EXE="$HOME/miniconda3/bin/python"
  55. PIP_CMD="$HOME/miniconda3/bin/pip"
  56. # Find the right wheel by grepping for the Python version.
  57. PYTHON_WHEEL="$(printf "%s\n" "$ROOT_DIR"/../../.whl/*"$PY_WHEEL_VERSION"* | head -n 1)"
  58. # Install the wheel.
  59. "$PIP_CMD" install -q "$PYTHON_WHEEL"
  60. # Check that ray.__commit__ was set properly.
  61. "$PYTHON_EXE" -u -c "import ray; print(ray.__commit__)" | grep "$TRAVIS_COMMIT" || (echo "ray.__commit__ not set properly!" && exit 1)
  62. # Install the dependencies to run the tests.
  63. "$PIP_CMD" install -q aiohttp aiosignal frozenlist grpcio 'pytest==7.0.1' requests proxy.py
  64. # Run a simple test script to make sure that the wheel works.
  65. for SCRIPT in "${TEST_SCRIPTS[@]}"; do
  66. retry "$PYTHON_EXE" "$SCRIPT"
  67. done
  68. retry "$PYTHON_EXE" "$DASHBOARD_TEST_SCRIPT"
  69. done
  70. # Check that the other wheels are present.
  71. NUMBER_OF_WHEELS="$(find "$ROOT_DIR"/../../.whl/ -mindepth 1 -maxdepth 1 -name "*.whl" | wc -l)"
  72. if [[ "$NUMBER_OF_WHEELS" != "4" ]]; then
  73. echo "Wrong number of wheels found."
  74. ls -l "$ROOT_DIR/../.whl/"
  75. exit 2
  76. fi
  77. elif [[ "$platform" == "macosx" ]]; then
  78. MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
  79. PY_WHEEL_VERSIONS=("36" "37" "38" "39")
  80. PY_MMS=("3.6"
  81. "3.7"
  82. "3.8"
  83. "3.9")
  84. for ((i=0; i<${#PY_MMS[@]}; ++i)); do
  85. PY_MM="${PY_MMS[i]}"
  86. PY_WHEEL_VERSION="${PY_WHEEL_VERSIONS[i]}"
  87. PYTHON_EXE="$MACPYTHON_PY_PREFIX/$PY_MM/bin/python$PY_MM"
  88. PIP_CMD="$(dirname "$PYTHON_EXE")/pip$PY_MM"
  89. # Find the appropriate wheel by grepping for the Python version.
  90. PYTHON_WHEEL="$(printf "%s\n" "$ROOT_DIR"/../../.whl/*"$PY_WHEEL_VERSION"* | head -n 1)"
  91. # Install the wheel.
  92. "$PIP_CMD" uninstall -y ray
  93. "$PIP_CMD" install -q "$PYTHON_WHEEL"
  94. # Install the dependencies to run the tests.
  95. "$PIP_CMD" install -q aiohttp aiosignal frozenlist grpcio 'pytest==7.0.1' requests proxy.py
  96. # Run a simple test script to make sure that the wheel works.
  97. for SCRIPT in "${TEST_SCRIPTS[@]}"; do
  98. PATH="$(dirname "$PYTHON_EXE"):$PATH" retry "$PYTHON_EXE" "$SCRIPT"
  99. done
  100. done
  101. elif [ "${platform}" = windows ]; then
  102. echo "WARNING: Wheel testing not yet implemented for Windows."
  103. else
  104. echo "Unrecognized environment."
  105. exit 3
  106. fi