diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 989cc17141..b8b23c1929 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -76,6 +76,7 @@ jobs: - name: Install run: | pwd + ./open_spiel/scripts/ci_python_prechecks.sh chmod +x install.sh ./install.sh - name: Build and test diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index bb6d42dced..de88640c54 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -34,7 +34,7 @@ jobs: OS_PYTHON_VERSION: 3.10 CIBW_ENVIRONMENT: "CXX=$(which g++) OPEN_SPIEL_BUILDING_WHEEL='ON' OPEN_SPIEL_BUILD_WITH_ACPC='ON' OPEN_SPIEL_BUILD_WITH_HANABI='ON' OPEN_SPIEL_BUILD_WITH_ROSHAMBO='ON'" CIBW_BUILD: cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 - - os: macOS-12 + - os: macOS-13 OS_TYPE: "Darwin" CI_PYBIN: python3.9 OS_PYTHON_VERSION: 3.9 diff --git a/open_spiel/scripts/ci_python_prechecks.sh b/open_spiel/scripts/ci_python_prechecks.sh new file mode 100755 index 0000000000..08c90b0d28 --- /dev/null +++ b/open_spiel/scripts/ci_python_prechecks.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Copyright 2019 DeepMind Technologies Ltd. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Only use for Github Actions CI! +OS=`uname -a | awk '{print $1}'` +if [[ "$OS" = "Darwin" ]]; then + # This seems to be necessary to install python via brew in Github Actions + rm -f /usr/local/bin/2to3-${OS_PYTHON_VERSION} + rm -f /usr/local/bin/idle${OS_PYTHON_VERSION} + rm -f /usr/local/bin/pydoc${OS_PYTHON_VERSION} + rm -f /usr/local/bin/python${OS_PYTHON_VERSION} + rm -f /usr/local/bin/python${OS_PYTHON_VERSION}* +fi + diff --git a/open_spiel/scripts/ci_script.sh b/open_spiel/scripts/ci_script.sh index fa33d68b3e..c2faba8c63 100755 --- a/open_spiel/scripts/ci_script.sh +++ b/open_spiel/scripts/ci_script.sh @@ -31,7 +31,6 @@ elif [[ "$OS" = "Darwin" ]]; then brew link --force python@${OS_PYTHON_VERSION} fi - PYBIN=${PYBIN:-"python${OS_PYTHON_VERSION}"} PYBIN=${PYBIN:-"python"} PYBIN=${PYBIN:-"python3"} diff --git a/open_spiel/scripts/install.sh b/open_spiel/scripts/install.sh index 24d72a1f91..c165952a66 100755 --- a/open_spiel/scripts/install.sh +++ b/open_spiel/scripts/install.sh @@ -33,6 +33,24 @@ ${PYBIN} --version MYDIR="$(dirname "$(realpath "$0")")" +# This function is only run on Github Actions! +function ci_check_install_python() { + if [[ ! "$CI" ]]; then + echo "Only run this function on Github Actions!" + exit 1 + fi + + # Need the trap here to make sure the return value of grep being 1 doesn't cause set -e to fail + # https://stackoverflow.com/questions/77047127/bash-capture-stderr-of-a-function-while-using-trap + trap 'ret=0; output=$(brew list --versions | grep "python ${OS_PYTHON_VERSION}") || ret="$?"; trap - RETURN' RETURN + if [[ "$output" = "" ]]; then + # The --force is needed because there seems to be a phantom installation in /usr/local/ + # and errors show up for files that already exist + brew install --force "python@${OS_PYTHON_VERSION}" + fi + return 0 +} + # Calling this file from the project root is not allowed, # as all the paths here are hard-coded to be relative to it. # @@ -288,11 +306,8 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX # On Github Actions, macOS comes with Python 3.9. # We want to test multiple Python versions determined by OS_PYTHON_VERSION. if [[ "$CI" ]]; then - # Only install the python version if it's not present. There are issues otherwise. - if [[ `brew list python@${OS_PYTHON_VERSION}; echo $?` == 0 ]]; then - brew install "python@${OS_PYTHON_VERSION}" - fi - # Uninstall Python 3.9 if we need to. + # Set brew to use the specific python version + ci_check_install_python brew link --force --overwrite "python@${OS_PYTHON_VERSION}" fi `python3 -c "import tkinter" > /dev/null 2>&1` || brew install tcl-tk || echo "** Warning: failed 'brew install tcl-tk' -- continuing"