#!/usr/bin/env bash
set -euxo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)"
WORKSPACE_DIR="${ROOT_DIR}/.."
PY_VERSIONS=("3.9" "3.10" "3.11" "3.12")
bazel_preclean() {
"${WORKSPACE_DIR}"/ci/run/bazel.py preclean "mnemonic(\"Genrule\", deps(//:*))"
}
get_python_version() {
python -s -c "import sys; sys.stdout.write('%s.%s' % sys.version_info[:2])"
}
is_python_version() {
local expected result=0
expected="$1"
case "$(get_python_version).0." in
"${expected}".*) ;;
*) result=1;;
esac
case "$(pip --version | tr -d "\r")" in
*" (python ${expected})") ;;
*) result=1;;
esac
return "${result}"
}
refreshenv() {
powershell -NonInteractive - <<\EOF
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
Update-SessionEnvironment
gci env:
Get-ChildItem env:* | %{
if (!($_.Name.Contains('('))) {
$value = $_.Value
if ($_.Name -eq 'PATH') {
$value = $value -replace ';',':'
}
Write-Output ("export " + $_.Name + "=$`(cat <<- 'REFRESHENV_EOF'`n" + $value + "`nREFRESHENV_EOF`)")
}
} | Out-File -Encoding ascii $env:TEMP\refreshenv.sh
EOF
source "$TEMP/refreshenv.sh"
}
install_ray() {
(
pip install wheel delvewheel
pushd python/ray/dashboard/client
choco install nodejs --version=22.4.1 -y
refreshenv
export NODE_OPTIONS=--openssl-legacy-provider
npm install
npm run build
popd
cd "${WORKSPACE_DIR}"/python
pip install -v -e .
)
}
uninstall_ray() {
pip uninstall -y ray
python -c $'import shutil; import sys; \nfor d in sys.argv[1:]: shutil.rmtree(d, ignore_errors=True);' \
"${ROOT_DIR}/ray/thirdparty_files" \
"${ROOT_DIR}/ray/_private/runtime_env/agent/thirdparty_files"
}
build_wheel_windows() {
local ray_uninstall_status=0
uninstall_ray || ray_uninstall_status=1
local local_dir="python/dist"
{
echo "build --announce_rc";
echo "build --config=ci";
echo "startup --output_user_root=c:/raytmp";
echo "build --remote_cache=${BUILDKITE_BAZEL_CACHE_URL}";
} >> ~/.bazelrc
if [[ "${BUILDKITE_PIPELINE_ID:-}" == "0189942e-0876-4b8f-80a4-617f988ec59b" || "${BUILDKITE_CACHE_READONLY:-}" == "true" ]]; then
echo "build --remote_upload_local_results=false" >> ~/.bazelrc
fi
for pyversion in "${PY_VERSIONS[@]}"; do
if [[ "${BUILD_ONE_PYTHON_ONLY:-}" != "" && "${pyversion}" != "${BUILD_ONE_PYTHON_ONLY}" ]]; then
continue
fi
bazel_preclean
git clean -q -f -f -x -d -e "${local_dir}" -e python/ray/dashboard/client
git checkout -q -f -- .
(
if ! is_python_version "${pyversion}"; then
conda install -y conda=24.1.2 python="${pyversion}"
fi
if ! is_python_version "${pyversion}"; then
echo "Expected pip for Python ${pyversion} but found Python $(get_python_version) with $(pip --version); exiting..." 1>&2
exit 1
fi
unset PYTHON2_BIN_PATH PYTHON3_BIN_PATH
install_ray
cd "${WORKSPACE_DIR}"/python
if [ -n "$BUILDKITE_COMMIT" ]; then
sed -i.bak "s/{{RAY_COMMIT_SHA}}/$BUILDKITE_COMMIT/g" ray/_version.py && rm ray/_version.py.bak
else
echo "BUILDKITE_COMMIT variable not set - required to populated ray.__commit__."
exit 1
fi
python -m pip wheel -q -w dist . --no-deps
delvewheel repair dist/ray-*.whl
RAY_INSTALL_CPP=1 python -m pip wheel -q -w dist . --no-deps
uninstall_ray
)
done
bazel_preclean
if [ 0 -eq "${ray_uninstall_status}" ]; then
install_ray
fi
}
build_wheel_windows "$@"