How to setup a Ray Distributed virtual environment for interactive development

I am a regular contributor to the Ray project. Every few months, I need to reset my local development environment for reasons that I'll get into later. I always forget the steps, so I'm writing them down here.

The nice thing about this setup is that edits to python/ray/{tune,train,serve,data,...} take effect immediately. This is great for quick test-debug cycles. However, this virtual environment is quite fragile and periodically breaks various reasons. The most common cause is:

...hence why I need to refresh my local dev environment periodically.

If reliability is a must, it's always better to build the Ray wheel yourself entirely from source.

# Based on the official 'Python-only' developer guide:
# https://docs.ray.io/en/latest/ray-contribute/development.html#building-ray-python-only
git clone [email protected]:ray-project/ray.git && cd ray

# Fresh venv
rm -rf .venv && python3 -m venv .venv && source .venv/bin/activate

# Nightly wheel
PY_VER=$(python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')")
# To find the wheel for other operating systems, see:
# https://docs.ray.io/en/latest/ray-overview/installation.html#daily-releases-nightlies
pip install -U "https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-3.0.0.dev0-cp${PY_VER}-cp${PY_VER}-macosx_12_0_arm64.whl"

# Deps
pip install fsspec pyarrow pandas pydantic

# Replace Python source with symlinks to your local code.
python python/ray/setup-dev.py -y

# Verify
python -c "import ray; import ray.tune; import ray.train; print('OK')"

Copyright Ricardo Decal. ricardodecal.com