build-wheel-windows.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. bazel_preclean() {
  7. "${WORKSPACE_DIR}"/ci/run/bazel.py preclean "mnemonic(\"Genrule\", deps(//:*))"
  8. }
  9. get_python_version() {
  10. python -s -c "import sys; sys.stdout.write('%s.%s' % sys.version_info[:2])"
  11. }
  12. is_python_version() {
  13. local expected result=0
  14. expected="$1"
  15. case "$(get_python_version).0." in
  16. "${expected}".*) ;;
  17. *) result=1;;
  18. esac
  19. case "$(pip --version | tr -d "\r")" in
  20. *" (python ${expected})") ;;
  21. *) result=1;;
  22. esac
  23. return "${result}"
  24. }
  25. refreshenv() {
  26. # https://gist.github.com/jayvdb/1daf8c60e20d64024f51ec333f5ce806
  27. powershell -NonInteractive - <<\EOF
  28. Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  29. Update-SessionEnvironment
  30. # Round brackets in variable names cause problems with bash
  31. Get-ChildItem env:* | %{
  32. if (!($_.Name.Contains('('))) {
  33. $value = $_.Value
  34. if ($_.Name -eq 'PATH') {
  35. $value = $value -replace ';',':'
  36. }
  37. Write-Output ("export " + $_.Name + "='" + $value + "'")
  38. }
  39. } | Out-File -Encoding ascii $env:TEMP\refreshenv.sh
  40. EOF
  41. source "$TEMP/refreshenv.sh"
  42. }
  43. install_ray() {
  44. # TODO(mehrdadn): This function should be unified with the one in ci/ci.sh.
  45. (
  46. pip install wheel
  47. pushd dashboard/client
  48. choco install nodejs -y
  49. refreshenv
  50. # https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
  51. export NODE_OPTIONS=--openssl-legacy-provider
  52. npm install
  53. npm run build
  54. popd
  55. cd "${WORKSPACE_DIR}"/python
  56. "${WORKSPACE_DIR}"/ci/keep_alive pip install -v -e .
  57. )
  58. }
  59. uninstall_ray() {
  60. pip uninstall -y ray
  61. python -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" clean "${ROOT_DIR}"/setup.py
  62. }
  63. build_wheel_windows() {
  64. local ray_uninstall_status=0
  65. uninstall_ray || ray_uninstall_status=1
  66. local local_dir="python/dist"
  67. for pyversion in "${PY_VERSIONS[@]}"; do
  68. if [ -z "${pyversion}" ]; then continue; fi
  69. bazel_preclean
  70. git clean -q -f -f -x -d -e "${local_dir}" -e python/ray/dashboard/client
  71. git checkout -q -f -- .
  72. # Start a subshell to prevent PATH and cd from affecting our shell environment
  73. (
  74. if ! is_python_version "${pyversion}"; then
  75. conda install -y python="${pyversion}"
  76. fi
  77. if ! is_python_version "${pyversion}"; then
  78. echo "Expected pip for Python ${pyversion} but found Python $(get_python_version) with $(pip --version); exiting..." 1>&2
  79. exit 1
  80. fi
  81. unset PYTHON2_BIN_PATH PYTHON3_BIN_PATH # make sure these aren't set by some chance
  82. install_ray
  83. cd "${WORKSPACE_DIR}"/python
  84. # Set the commit SHA in __init__.py.
  85. if [ -n "$BUILDKITE_COMMIT" ]; then
  86. sed -i.bak "s/{{RAY_COMMIT_SHA}}/$BUILDKITE_COMMIT/g" ray/__init__.py && rm ray/__init__.py.bak
  87. else
  88. echo "BUILDKITE_COMMIT variable not set - required to populated ray.__commit__."
  89. exit 1
  90. fi
  91. # build ray wheel
  92. python setup.py --quiet bdist_wheel
  93. # build ray-cpp wheel
  94. RAY_INSTALL_CPP=1 python setup.py --quiet bdist_wheel
  95. uninstall_ray
  96. )
  97. done
  98. bazel_preclean
  99. if [ 0 -eq "${ray_uninstall_status}" ]; then # If Ray was previously installed, restore it
  100. install_ray
  101. fi
  102. }
  103. build_wheel_windows "$@"