Skip to content

Commit 4f418da

Browse files
committed
Merge pull request #1418 from google-deepmind:lanctot-patch-79
PiperOrigin-RevId: 851335503 Change-Id: If37669b43b622e21beb0abee6e5f11a536281130
2 parents ba14f57 + 6682ef9 commit 4f418da

File tree

4 files changed

+41
-45
lines changed

4 files changed

+41
-45
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ jobs:
2525
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
2626
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
2727
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
28-
- os: ubuntu-22.04
28+
- os: ubuntu-24.04
2929
OS_PYTHON_VERSION: "3.11"
3030
DEFAULT_OPTIONAL_DEPENDENCY: "ON"
3131
BUILD_SHARED_LIB: "OFF"
32-
OPEN_SPIEL_ABSL_VERSION: "20230125.0"
32+
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
3333
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
3434
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
35-
# Standard (most current) platforms and versions.
36-
- os: ubuntu-22.04
35+
- os: ubuntu-24.04
3736
OS_PYTHON_VERSION: "3.10"
3837
DEFAULT_OPTIONAL_DEPENDENCY: "OFF"
3938
BUILD_SHARED_LIB: "OFF"
40-
OPEN_SPIEL_ABSL_VERSION: "20230125.0"
39+
OPEN_SPIEL_ABSL_VERSION: "20250127.1"
4140
OPEN_SPIEL_BUILD_WITH_ORTOOLS: "OFF"
4241
OPEN_SPIEL_BUILD_WITH_ORTOOLS_DOWNLOAD_URL: ""
4342
- os: macos-14
@@ -67,6 +66,9 @@ jobs:
6766
- uses: julia-actions/setup-julia@v2
6867
with:
6968
version: 1.8
69+
- uses: actions/setup-python@v6
70+
with:
71+
python-version: ${{ matrix.OS_PYTHON_VERSION }}
7072
- name: Ad-hoc fix
7173
if: ${{ matrix.DEFAULT_OPTIONAL_DEPENDENCY == 'ON' }}
7274
run: |

open_spiel/python/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
if (OPEN_SPIEL_BUILDING_WHEEL)
32
# When building a wheel, need to use this. See:
43
# https://github.com/joerick/cibuildwheel/issues/639#issuecomment-817872369
@@ -341,10 +340,17 @@ set(WHEEL_EXCLUDED_PYTHON_TESTS
341340
games/tic_tac_toe_test.py
342341
../integration_tests/playthrough_test.py)
343342

343+
# Prefer to use PYBIN as the executable if it's defined (e.g. on GitHub CI)
344+
if(NOT DEFINED ENV{PYBIN})
345+
set(PYBIN ${Python3_EXECUTABLE})
346+
else()
347+
set(PYBIN $ENV{PYBIN})
348+
endif()
349+
344350
# Create a python test.
345351
foreach(py_test_file IN LISTS PYTHON_TESTS)
346352
if (NOT (OPEN_SPIEL_BUILDING_WHEEL AND ${py_test_file} IN_LIST WHEEL_EXCLUDED_PYTHON_TESTS))
347-
add_test(NAME python/${py_test_file} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})
353+
add_test(NAME python/${py_test_file} COMMAND ${PYBIN} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_file})
348354

349355
# We need two elements in the python path: CURRENT_BINARY_DIR to pick up
350356
# pyspiel.so, and CURRENT_SOURCE_DIR for the Python source files. We use
@@ -361,7 +367,7 @@ endforeach(py_test_file)
361367
# We don't generate these automatically because we may want custom parameters.
362368
if (OPEN_SPIEL_ENABLE_JAX AND NOT OPEN_SPIEL_BUILDING_WHEEL)
363369
add_test(NAME python_examples_bridge_supervised_learning
364-
COMMAND ${Python3_EXECUTABLE}
370+
COMMAND ${PYBIN}
365371
${CMAKE_CURRENT_SOURCE_DIR}/examples/bridge_supervised_learning.py
366372
--iterations 10
367373
--eval_every 5

open_spiel/scripts/build_and_run_tests.sh

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
# Load argslib for parsing of command-line arguments.
3636
source $(dirname "$0")/argslib.sh
3737

38+
ArgsLibAddArg github_ci bool false "Whether running from github CI."
3839
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."
3940
# We define a string and not a boolean, because we can to know whether this flag
4041
# has been explicitly set or not.
@@ -52,8 +53,11 @@ function die() {
5253
exit -1
5354
}
5455

55-
set -e # exit when any command fails
56-
# set -x # Prints all executed command
56+
if [[ $ARG_github_ci == "true" ]]; then
57+
echo "GitHub CI detected. Setting -e and -x"
58+
set -e
59+
set -x
60+
fi
5761

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

8286
echo -e "\e[33mRunning ${0} from $PWD\e[0m"
83-
PYBIN=${PYBIN:-"python3"}
84-
PYBIN=`which ${PYBIN}`
85-
if [ ! -x $PYBIN ]
87+
echo -e "Trying to find 'python'"
88+
PYBIN=`which python`
89+
if [[ ! -x $PYBIN ]]
8690
then
87-
echo -e "\e[1m\e[93m$PYBIN not found! Skip build and test.\e[0m"
88-
continue
91+
echo -e "python not found, trying to find python3..."
92+
PYBIN=`which python3`
93+
if [[ ! -x $PYBIN ]]
94+
then
95+
echo -e "\e[1m\e[93m$PYBIN not found! Skip build and test.\e[0m"
96+
exit 1
97+
fi
8998
fi
99+
echo "PYBIN is $PYBIN"
90100

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

101111
VENV_DIR="./venv"
@@ -118,9 +128,9 @@ if [[ $ARG_virtualenv == "true" ]]; then
118128
fi
119129
PYBIN=python
120130
source $VENV_DIR/bin/activate
121-
# When you're in a virtual environment, the python binary should be just python3.
131+
# When you're in a virtual environment, the python binary should be just python.
122132
# Otherwise, it uses the environment's python.
123-
PYBIN="python3"
133+
PYBIN="python"
124134
fi
125135

126136
# We only exit the virtualenv if we were asked to create one.

open_spiel/scripts/ci_script.sh

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,14 @@
1717
set -e
1818
set -x
1919

20-
# Python 3.9 not default on Ubuntu yet (Ubuntu 20.04).
21-
OS=`uname -a | awk '{print $1}'`
22-
if [[ "$OS" = "Linux" && "$OS_PYTHON_VERSION" = "3.9" ]]; then
23-
echo "Linux detected and Python 3.9 requested. Installing Python 3.9 and setting as default."
24-
sudo apt-get install python3.9 python3.9-dev
25-
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
26-
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
27-
# Still needed to support using venv on Ubuntu 20.04:
28-
sudo apt-get install python3.9-venv
29-
elif [[ "$OS" = "Darwin" ]]; then
30-
# Python is already intalled via brew in install.sh from actions.yml
31-
brew link --force python@${OS_PYTHON_VERSION}
32-
fi
33-
3420
PYBIN=${PYBIN:-"python${OS_PYTHON_VERSION}"}
3521
PYBIN=${PYBIN:-"python"}
3622
PYBIN=${PYBIN:-"python3"}
3723
PYBIN=`which $PYBIN`
3824

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

41-
if [[ "$OS" = "Linux" && ( "$OS_PYTHON_VERSION" = "3.9" || "$OS_PYTHON_VERSION" = "3.10" || "$OS_PYTHON_VERSION" = "3.11" || "$OS_PYTHON_VERSION" = "3.12" ) ]]; then
42-
# Ubuntu 22.04 must execute the virtual env this way:
43-
${PYBIN} -m venv ./venv
44-
elif [[ "$OS" = "Darwin" && ( "$OS_PYTHON_VERSION" = "3.12" || "$OS_PYTHON_VERSION" = "3.13" ) ]]; then
45-
${PYBIN} -m venv ./venv
46-
else
47-
# Ubuntu 20.04 and earlier
48-
${PYBIN} -m pip install virtualenv
49-
virtualenv -p ${PYBIN} ./venv
50-
fi
51-
27+
${PYBIN} -m venv ./venv
5228
source ./venv/bin/activate
5329

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

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

6846
deactivate

0 commit comments

Comments
 (0)