Skip to content
12 changes: 7 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ jobs:
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
- os: ubuntu-22.04
- os: ubuntu-24.04
OS_PYTHON_VERSION: "3.11"
DEFAULT_OPTIONAL_DEPENDENCY: "ON"
BUILD_SHARED_LIB: "OFF"
OPEN_SPIEL_ABSL_VERSION: "20230125.0"
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
# Standard (most current) platforms and versions.
- os: ubuntu-22.04
- os: ubuntu-24.04
OS_PYTHON_VERSION: "3.10"
DEFAULT_OPTIONAL_DEPENDENCY: "OFF"
BUILD_SHARED_LIB: "OFF"
OPEN_SPIEL_ABSL_VERSION: "20230125.0"
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
- os: macos-14
Expand Down Expand Up @@ -67,6 +66,9 @@ jobs:
- uses: julia-actions/setup-julia@v2
with:
version: 1.8
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.OS_PYTHON_VERSION }}
- name: Ad-hoc fix
if: ${{ matrix.DEFAULT_OPTIONAL_DEPENDENCY == 'ON' }}
run: |
Expand Down
12 changes: 9 additions & 3 deletions open_spiel/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

if (OPEN_SPIEL_BUILDING_WHEEL)
# When building a wheel, need to use this. See:
# https://github.com/joerick/cibuildwheel/issues/639#issuecomment-817872369
Expand Down Expand Up @@ -341,10 +340,17 @@ set(WHEEL_EXCLUDED_PYTHON_TESTS
games/tic_tac_toe_test.py
../integration_tests/playthrough_test.py)

# Prefer to use PYBIN as the executable if it's defined (e.g. on GitHub CI)
if(NOT DEFINED ENV{PYBIN})
set(PYBIN ${Python3_EXECUTABLE})
else()
set(PYBIN $ENV{PYBIN})
endif()

# Create a python test.
foreach(py_test_file IN LISTS PYTHON_TESTS)
if (NOT (OPEN_SPIEL_BUILDING_WHEEL AND ${py_test_file} IN_LIST WHEEL_EXCLUDED_PYTHON_TESTS))
add_test(NAME python/${py_test_file} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})
add_test(NAME python/${py_test_file} COMMAND ${PYBIN} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})

# We need two elements in the python path: CURRENT_BINARY_DIR to pick up
# pyspiel.so, and CURRENT_SOURCE_DIR for the Python source files. We use
Expand All @@ -361,7 +367,7 @@ endforeach(py_test_file)
# We don't generate these automatically because we may want custom parameters.
if (OPEN_SPIEL_ENABLE_JAX AND NOT OPEN_SPIEL_BUILDING_WHEEL)
add_test(NAME python_examples_bridge_supervised_learning
COMMAND ${Python3_EXECUTABLE}
COMMAND ${PYBIN}
${CMAKE_CURRENT_SOURCE_DIR}/examples/bridge_supervised_learning.py
--iterations 10
--eval_every 5
Expand Down
32 changes: 21 additions & 11 deletions open_spiel/scripts/build_and_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# Load argslib for parsing of command-line arguments.
source $(dirname "$0")/argslib.sh

ArgsLibAddArg github_ci bool false "Whether running from github CI."
ArgsLibAddArg virtualenv bool true "Whether to use virtualenv. We enter a virtualenv (stored in venv/) only if this flag is true and we are not already in one."
# We define a string and not a boolean, because we can to know whether this flag
# has been explicitly set or not.
Expand All @@ -52,8 +53,11 @@ function die() {
exit -1
}

set -e # exit when any command fails
# set -x # Prints all executed command
if [[ $ARG_github_ci == "true" ]]; then
echo "GitHub CI detected. Setting -e and -x"
set -e
set -x
fi

MYDIR="$(dirname "$(realpath "$0")")"
source "${MYDIR}/global_variables.sh"
Expand All @@ -80,22 +84,28 @@ else
fi

echo -e "\e[33mRunning ${0} from $PWD\e[0m"
PYBIN=${PYBIN:-"python3"}
PYBIN=`which ${PYBIN}`
if [ ! -x $PYBIN ]
echo -e "Trying to find 'python'"
PYBIN=`which python`
if [[ ! -x $PYBIN ]]
then
echo -e "\e[1m\e[93m$PYBIN not found! Skip build and test.\e[0m"
continue
echo -e "python not found, trying to find python3..."
PYBIN=`which python3`
if [[ ! -x $PYBIN ]]
then
echo -e "\e[1m\e[93m$PYBIN not found! Skip build and test.\e[0m"
exit 1
fi
fi
echo "PYBIN is $PYBIN"

# if we are in a virtual_env, we will not create a new one inside.
if [[ "$VIRTUAL_ENV" != "" ]]
then
echo -e "\e[1m\e[93mVirtualenv already detected. We do not create a new one.\e[0m"
ArgsLibSet virtualenv false
# When you're in a virtual environment, the python binary should be just python3.
# When you're in a virtual environment, the python binary should be just python.
# Otherwise, it uses the environment's python.
PYBIN="python3"
PYBIN="python"
fi

VENV_DIR="./venv"
Expand All @@ -118,9 +128,9 @@ if [[ $ARG_virtualenv == "true" ]]; then
fi
PYBIN=python
source $VENV_DIR/bin/activate
# When you're in a virtual environment, the python binary should be just python3.
# When you're in a virtual environment, the python binary should be just python.
# Otherwise, it uses the environment's python.
PYBIN="python3"
PYBIN="python"
fi

# We only exit the virtualenv if we were asked to create one.
Expand Down
30 changes: 4 additions & 26 deletions open_spiel/scripts/ci_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,14 @@
set -e
set -x

# Python 3.9 not default on Ubuntu yet (Ubuntu 20.04).
OS=`uname -a | awk '{print $1}'`
if [[ "$OS" = "Linux" && "$OS_PYTHON_VERSION" = "3.9" ]]; then
echo "Linux detected and Python 3.9 requested. Installing Python 3.9 and setting as default."
sudo apt-get install python3.9 python3.9-dev
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# Still needed to support using venv on Ubuntu 20.04:
sudo apt-get install python3.9-venv
elif [[ "$OS" = "Darwin" ]]; then
# Python is already intalled via brew in install.sh from actions.yml
brew link --force python@${OS_PYTHON_VERSION}
fi

PYBIN=${PYBIN:-"python${OS_PYTHON_VERSION}"}
PYBIN=${PYBIN:-"python"}
PYBIN=${PYBIN:-"python3"}
PYBIN=`which $PYBIN`

source ./open_spiel/scripts/python_extra_deps.sh $PYBIN

if [[ "$OS" = "Linux" && ( "$OS_PYTHON_VERSION" = "3.9" || "$OS_PYTHON_VERSION" = "3.10" || "$OS_PYTHON_VERSION" = "3.11" || "$OS_PYTHON_VERSION" = "3.12" ) ]]; then
# Ubuntu 22.04 must execute the virtual env this way:
${PYBIN} -m venv ./venv
elif [[ "$OS" = "Darwin" && ( "$OS_PYTHON_VERSION" = "3.12" || "$OS_PYTHON_VERSION" = "3.13" ) ]]; then
${PYBIN} -m venv ./venv
else
# Ubuntu 20.04 and earlier
${PYBIN} -m pip install virtualenv
virtualenv -p ${PYBIN} ./venv
fi

${PYBIN} -m venv ./venv
source ./venv/bin/activate

pip install --upgrade pip
Expand All @@ -63,6 +39,8 @@ pip install --upgrade -r requirements.txt
[[ "$OPEN_SPIEL_ENABLE_PYTORCH" = "ON" ]] && pip install --no-cache-dir --upgrade $OPEN_SPIEL_PYTHON_PYTORCH_DEPS
[[ "$OPEN_SPIEL_ENABLE_PYTHON_MISC" = "ON" ]] && pip install --no-cache-dir --upgrade $OPEN_SPIEL_PYTHON_MISC_DEPS

./open_spiel/scripts/build_and_run_tests.sh
# We need PYBIN to be python on its own so that the build and run script
# finds the one from the virtual environment.
PYBIN="python" ./open_spiel/scripts/build_and_run_tests.sh --github_ci=true

deactivate
Loading