Skip to content

Commit de39c08

Browse files
committed
Use cmake-derived Python executable.
1 parent 7ad1c44 commit de39c08

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ add_wheel_test(mylib-test
107107
)
108108
```
109109

110+
By default, `add_wheel_test(...)` creates the temporary virtual environment using the same `Python3_EXECUTABLE` that CMake found. To override the interpreter used for the venv, set `PYTHON_WHEEL_TEST_EXECUTABLE` in the environment at configure time, or override the test's `ENVIRONMENT` property.
111+
110112
## Building Docker Images
111113

112114
To build the manylinux Docker images for different architectures:

python-wheel.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ function (add_wheel_test TEST_NAME)
220220
"WORKING_DIRECTORY"
221221
"COMMANDS" ${ARGN})
222222

223+
set(wheel_test_python_executable "${Python3_EXECUTABLE}")
224+
if (DEFINED ENV{PYTHON_WHEEL_TEST_EXECUTABLE} AND NOT "$ENV{PYTHON_WHEEL_TEST_EXECUTABLE}" STREQUAL "")
225+
set(wheel_test_python_executable "$ENV{PYTHON_WHEEL_TEST_EXECUTABLE}")
226+
endif()
227+
file(TO_CMAKE_PATH "${wheel_test_python_executable}" wheel_test_python_executable_cmake_path)
228+
223229
add_test(
224230
NAME
225231
${TEST_NAME}
@@ -229,4 +235,7 @@ function (add_wheel_test TEST_NAME)
229235
bash "${TEST_WHEEL_BASH}"
230236
-w "${WHEEL_DEPLOY_DIRECTORY}"
231237
${WHEEL_TEST_COMMANDS})
238+
239+
set_property(TEST ${TEST_NAME} APPEND PROPERTY
240+
ENVIRONMENT "PYTHON_WHEEL_TEST_EXECUTABLE=${wheel_test_python_executable_cmake_path}")
232241
endfunction()

test-wheel.bash

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
set -e
44

5-
my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6-
. "$my_dir/python.bash"
5+
venv_python="${PYTHON_WHEEL_TEST_EXECUTABLE:-}"
6+
if [[ -z "$venv_python" ]]; then
7+
echo "PYTHON_WHEEL_TEST_EXECUTABLE is not set; using 'python3' from PATH." >&2
8+
venv_python="python3"
9+
fi
710

811
venv=$(mktemp -d)
9-
echo "→ Setting up a virtual environment in $venv using python '$(which python3)' ($(python3 --version))..."
10-
python3 -m venv "$venv"
12+
echo "→ Setting up a virtual environment in $venv using python '$venv_python' ($("$venv_python" --version))..."
13+
14+
"$venv_python" -m venv "$venv"
15+
16+
activate_path="bin/activate"
17+
if [[ -f "$venv/Scripts/activate" ]]; then
18+
activate_path="Scripts/activate"
19+
fi
20+
21+
# shellcheck disable=SC1090
1122
source "$venv/$activate_path"
23+
1224
python -m pip install -U pip
1325
pip install pytest
1426

@@ -18,7 +30,7 @@ trap '
1830
failed_pids=()
1931
for pid in $(jobs -p); do
2032
if kill -0 $pid >/dev/null 2>&1; then
21-
# Background process is still running - good.
33+
# Background process is still running - kill it.
2234
kill $pid
2335
else
2436
exit_status=$?

0 commit comments

Comments
 (0)