Skip to content

Commit

Permalink
Asserting Python version in minimal tests
Browse files Browse the repository at this point in the history
Signed-off-by: Cade Daniel <cade@anyscale.com>
  • Loading branch information
cadedaniel committed Jun 27, 2023
1 parent 0c13e54 commit 7aa1d54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ test_minimal() {
./ci/env/install-minimal.sh "$1"
echo "Installed minimal dependencies."
./ci/env/env_info.sh
python ./ci/env/check_minimal_install.py
python ./ci/env/check_minimal_install.py "$1"
run_minimal_test "$1"
}

Expand Down
16 changes: 16 additions & 0 deletions ci/env/check_minimal_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
This is to ensure that tests with minimal dependencies are not tainted
by too many installed packages.
It also ensures the correct Python version.
"""

from typing import List
import argparse
import sys

# These are taken from `setup.py` for ray[default]
DEFAULT_BLACKLIST = [
Expand Down Expand Up @@ -46,6 +50,18 @@ def assert_packages_not_installed(blacklist: List[str]):
f"current Python environment: {blacklist}"
)

def assert_python_version(expected_python_version: str) -> None:
actual_major, actual_minor = sys.version_info[:2]
actual_version = f'{actual_major}.{actual_minor}'
expected_version = expected_python_version.strip()
assert expected_version == actual_version, f"Expected Python version {expected_version=}, {actual_version=}"


if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument("--expected-python-version", type=str, required=True, help="Expected Python version in MAJOR.MINOR format, e.g. 3.11")
args = parser.parse_args()

assert_packages_not_installed(DEFAULT_BLACKLIST)
assert_python_version(args.expected_python_version)
4 changes: 3 additions & 1 deletion ci/env/install-minimal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
if [ "$1" == "3.11" ]; then
# TODO: fix build wheels unsupported tags in the future
echo "'set -xe' not working for Python 3.11"
echo "[cade] setting -xe anyways"
set -xe
else
set -xe
fi
Expand Down Expand Up @@ -32,7 +34,7 @@ echo "Python version is ${PYTHON_VERSION}"
ROOT_DIR=$(cd "$(dirname "$0")/$(dirname "$(test -L "$0" && readlink "$0" || echo "/")")" || exit; pwd)
WORKSPACE_DIR="${ROOT_DIR}/../.."

# Installs conda and python 3.7
# Installs conda and the specified python version
MINIMAL_INSTALL=1 PYTHON=${PYTHON_VERSION} "${WORKSPACE_DIR}/ci/env/install-dependencies.sh"

# Re-install Ray wheels
Expand Down

0 comments on commit 7aa1d54

Please sign in to comment.