|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2026 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -e |
| 17 | +set -x |
| 18 | + |
| 19 | +# For pyenv python installation on ml-build image |
| 20 | +sudo apt-get update |
| 21 | +sudo apt-get install -y libbz2-dev liblzma-dev libncurses-dev libffi-dev libssl-dev libreadline-dev libsqlite3-dev zlib1g-dev |
| 22 | + |
| 23 | +PYENV_ROOT="$HOME/.pyenv" |
| 24 | +PYTHON_VERSION=${PYTHON_VERSION:-"3.11"} |
| 25 | + |
| 26 | +function force_tensorflow_version() { |
| 27 | + if [[ -z "${TF_VERSION}" ]]; then |
| 28 | + echo "TF_VERSION is not set. Not forcing tensorflow version." |
| 29 | + return |
| 30 | + fi |
| 31 | + |
| 32 | + pip install tensorflow=="${TF_VERSION}" --progress-bar off --upgrade |
| 33 | + if [[ "$TF_USE_LEGACY_KERAS" == 1 ]]; then |
| 34 | + pip install tf-keras=="${TF_VERSION}" --progress-bar off --upgrade |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +echo "Installing pyenv.." |
| 39 | +git clone https://github.com/pyenv/pyenv.git "$PYENV_ROOT" |
| 40 | +export PATH="$HOME/.local/bin:$PYENV_ROOT/bin:$PATH" |
| 41 | +eval "$(pyenv init --path)" |
| 42 | + |
| 43 | +echo "Python setup..." |
| 44 | +pyenv install -s "$PYTHON_VERSION" |
| 45 | +pyenv global "$PYTHON_VERSION" |
| 46 | + |
| 47 | +PIP_TEST_PREFIX=bazel_pip |
| 48 | + |
| 49 | +python -m venv build_venv |
| 50 | +source build_venv/bin/activate |
| 51 | + |
| 52 | +# Debug messages to indicate the python version |
| 53 | +python --version |
| 54 | + |
| 55 | +# update pip |
| 56 | +pip install --upgrade pip |
| 57 | + |
| 58 | +# Install build |
| 59 | +pip install build |
| 60 | + |
| 61 | +TEST_ROOT=$(pwd)/${PIP_TEST_PREFIX} |
| 62 | +rm -rf "$TEST_ROOT" |
| 63 | +mkdir -p "$TEST_ROOT" |
| 64 | +ln -s "$(pwd)"/tensorflow_gnn "$TEST_ROOT"/tensorflow_gnn |
| 65 | + |
| 66 | +# Print the OS version |
| 67 | +cat /etc/os-release |
| 68 | + |
| 69 | +# Prepend common tag filters to a defined env_var |
| 70 | +# For example, tests for TF 2.8 shouldn't run RNG-dependent tests |
| 71 | +# These tag filters are enforced to start with a comma for separation |
| 72 | +tag_filters="-no_oss,-oss_excluded${TAG_FILTERS}" |
| 73 | + |
| 74 | +# Check that `bazel` does version selection as expected. |
| 75 | +if [[ -n "${USE_BAZEL_VERSION}" && $(bazel --version) != *${USE_BAZEL_VERSION}* ]]; then |
| 76 | + echo "Mismatch of configured and actual bazel version (see logged [[ command)" |
| 77 | + exit 1 |
| 78 | +fi |
| 79 | + |
| 80 | +bazel clean |
| 81 | + |
| 82 | +if [[ "$TEST_TF_NIGHTLY" == "true" ]]; then |
| 83 | + pip install --group test-nightly --progress-bar off --upgrade |
| 84 | +else |
| 85 | + force_tensorflow_version |
| 86 | +fi |
| 87 | + |
| 88 | +python3 -m build --wheel |
| 89 | +deactivate |
| 90 | + |
| 91 | +# Start the test environment. |
| 92 | +python3 -m venv test_venv |
| 93 | +source test_venv/bin/activate |
| 94 | + |
| 95 | +# Check the python version |
| 96 | +python --version |
| 97 | + |
| 98 | +# update pip |
| 99 | +pip install --upgrade pip |
| 100 | + |
| 101 | +if [[ "$TEST_TF_NIGHTLY" == "true" ]]; then |
| 102 | + pip install dist/tensorflow_gnn-*.whl |
| 103 | + tf_wheel=$(ls dist/tensorflow_gnn-*.whl) |
| 104 | + pip install "${tf_wheel[0]}[vizier]" |
| 105 | + pip uninstall -y tensorflow tf-keras ai-edge-litert |
| 106 | + pip install --group test-nightly --progress-bar off --upgrade |
| 107 | + |
| 108 | + # Check that tf-nightly is installed but tensorflow is not |
| 109 | + # Also check that tf-keras-nightly is installed. |
| 110 | + if [[ $(pip freeze | grep -q tf_nightly=; echo $?) -eq 0 && $(pip freeze | grep -q tensorflow=; echo $?) -eq 0 ]]; then |
| 111 | + echo "Found tensorflow and tf_nightly in the environment." |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | + if [[ $(pip freeze | grep -q tf_keras-nightly=; echo $?) -eq 0 && $(pip freeze | grep -q tf_keras=; echo $?) -eq 0 ]]; then |
| 115 | + echo "Found tf_keras and tf_keras-nightly in the environment." |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + |
| 119 | +else |
| 120 | + force_tensorflow_version |
| 121 | + pip install --group test-released --progress-bar off --upgrade |
| 122 | + pip install dist/tensorflow_gnn-*.whl |
| 123 | +fi |
| 124 | + |
| 125 | +echo "Final packages after all pip commands:" |
| 126 | +pip list |
| 127 | + |
| 128 | +bazel test --test_env=TF_USE_LEGACY_KERAS --build_tag_filters="${tag_filters}" --test_tag_filters="${tag_filters}" --test_output=errors --verbose_failures=true --build_tests_only --define=no_tfgnn_py_deps=true --keep_going --experimental_repo_remote_exec //bazel_pip/tensorflow_gnn/... |
0 commit comments