build-wheel-windows.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. set -euxo pipefail
  3. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)"
  4. WORKSPACE_DIR="${ROOT_DIR}/.."
  5. PY_VERSIONS=($(python -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" python_versions "${ROOT_DIR}"/setup.py | tr -d "\r"))
  6. PY_SCRIPT_SUBDIR=Scripts # 'bin' for UNIX, 'Scripts' for Windows
  7. bazel_preclean() {
  8. "${WORKSPACE_DIR}"/ci/travis/bazel.py preclean "mnemonic(\"Genrule\", deps(//:*))"
  9. }
  10. get_python_version() {
  11. python -s -c "import sys; sys.stdout.write('%s.%s' % sys.version_info[:2])"
  12. }
  13. is_python_version() {
  14. local expected result=0
  15. expected="$1"
  16. case "$(get_python_version).0." in
  17. "${expected}".*) ;;
  18. *) result=1;;
  19. esac
  20. case "$(pip --version | tr -d "\r")" in
  21. *" (python ${expected})") ;;
  22. *) result=1;;
  23. esac
  24. return "${result}"
  25. }
  26. install_ray() {
  27. # TODO(mehrdadn): This function should be unified with the one in ci/travis/ci.sh.
  28. (
  29. pip install wheel
  30. cd "${WORKSPACE_DIR}"/python
  31. "${WORKSPACE_DIR}"/ci/keep_alive pip install -v -e .
  32. )
  33. }
  34. uninstall_ray() {
  35. pip uninstall -y ray
  36. python -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" clean "${ROOT_DIR}"/setup.py
  37. }
  38. build_wheel_windows() {
  39. local ray_uninstall_status=0
  40. uninstall_ray || ray_uninstall_status=1
  41. local pyversion pyversions=()
  42. for pyversion in "${PY_VERSIONS[@]}"; do
  43. if [ "${pyversion}" = "${PYTHON-}" ]; then continue; fi # we'll build ${PYTHON} last
  44. pyversions+=("${pyversion}")
  45. done
  46. pyversions+=("${PYTHON-}") # build this last so any subsequent steps use the right version
  47. local local_dir="python/dist"
  48. for pyversion in "${pyversions[@]}"; do
  49. if [ -z "${pyversion}" ]; then continue; fi
  50. bazel_preclean
  51. git clean -q -f -f -x -d -e "${local_dir}" -e python/ray/dashboard/client
  52. git checkout -q -f -- .
  53. # Start a subshell to prevent PATH and cd from affecting our shell environment
  54. (
  55. if ! is_python_version "${pyversion}"; then
  56. local pydirs=("${RUNNER_TOOL_CACHE}/Python/${pyversion}".*/x64)
  57. local pydir="${pydirs[-1]}"
  58. pydir="$(cygpath -u "${pydir}")" # Translate Windows path
  59. test -d "${pydir}"
  60. export PATH="${pydir}:${pydir}/${PY_SCRIPT_SUBDIR}:${PATH}"
  61. fi
  62. if ! is_python_version "${pyversion}"; then
  63. echo "Expected pip for Python ${pyversion} but found Python $(get_python_version) with $(pip --version); exiting..." 1>&2
  64. exit 1
  65. fi
  66. unset PYTHON2_BIN_PATH PYTHON3_BIN_PATH # make sure these aren't set by some chance
  67. install_ray
  68. cd "${WORKSPACE_DIR}"/python
  69. python setup.py --quiet bdist_wheel
  70. uninstall_ray
  71. )
  72. done
  73. bazel_preclean
  74. if [ 0 -eq "${ray_uninstall_status}" ]; then # If Ray was previously installed, restore it
  75. install_ray
  76. fi
  77. }
  78. build_wheel_windows "$@"