build-wheel-windows.sh 3.9 KB

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