This is an automated email from the ASF dual-hosted git repository. astitcher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 99684736d0a9c7270e126217c8f19f1488fa605d Author: Andrew Stitcher <astitc...@apache.org> AuthorDate: Fri Jul 14 17:56:23 2023 -0400 PROTON-2756: Allow python testing to use the python detected by CMake This is comtrolled by a new CMake option called ENABLE_PYTHON_TEST_VENV If the build system is not connected to the internet then building a virtual environment to test the python binding can be a problem so allow the build to use the installation of python that was detected by CMake to test the python binding. Testing using a completely clean environment made for the purpose will be more reliable for internet connected systems so using the venv is the default. Since the switch to using cffi instead of swig this is required for testing to work and for building wheels. So we make sure that we have cffi installed before we allow python testing or wheel building. --- python/CMakeLists.txt | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1972772f8..2e576d24f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -148,9 +148,10 @@ add_custom_command(OUTPUT ./tox.ini # Make python source and binary packages if we have prerequisistes check_python_module("setuptools" SETUPTOOLS_MODULE_FOUND) check_python_module("wheel" WHEEL_MODULE_FOUND) +check_python_module("cffi" CFFI_MODULE_FOUND) if (SETUPTOOLS_MODULE_FOUND) set (pydist_cmds sdist) - if (WHEEL_MODULE_FOUND) + if (WHEEL_MODULE_FOUND AND CFFI_MODULE_FOUND) set (pydist_cmds sdist bdist_wheel --py-limited-api=cp38) endif() endif() @@ -184,24 +185,32 @@ if (BUILD_TESTING) set (python_coverage_options -m coverage run --parallel-mode) endif(CMAKE_BUILD_TYPE MATCHES "Coverage") - # Create Python virtual environment to run tests - set(pytest_venv "${py_bin}/pytest_env") - # Have to use a conditional here as you can't use generator expressions in OUTPUT or BYPRODUCTS - if (WIN32) - set(py_venv_bin "Scripts") + option(ENABLE_PYTHON_TEST_VENV "Enable python testing within a separate virtual environment." ON) + if (ENABLE_PYTHON_TEST_VENV) + # Create Python virtual environment to run tests + set(pytest_venv "${py_bin}/pytest_env") + # Have to use a conditional here as you can't use generator expressions in OUTPUT or BYPRODUCTS + if (WIN32) + set(py_venv_bin "Scripts") + else() + set(py_venv_bin "bin") + endif() + set(pytest_bin "${pytest_venv}/${py_venv_bin}") + set(pytest_executable "${pytest_bin}/python${CMAKE_EXECUTABLE_SUFFIX}") + + add_custom_command( + OUTPUT ${pytest_venv}/env.txt + COMMAND ${Python_EXECUTABLE} -m venv ${pytest_venv} + COMMAND ${pytest_executable} -m pip install --disable-pip-version-check cffi setuptools + COMMAND ${pytest_executable} -m pip freeze > ${pytest_venv}/env.txt + BYPRODUCTS ${pytest_executable} + ) + else() - set(py_venv_bin "bin") + set(pytest_executable "${Python_EXECUTABLE}") + set(pytest_venv "${py_bin}") + FILE(TOUCH "${pytest_venv}/env.txt") endif() - set(pytest_bin "${pytest_venv}/${py_venv_bin}") - set(pytest_executable "${pytest_bin}/python${CMAKE_EXECUTABLE_SUFFIX}") - - add_custom_command( - OUTPUT ${pytest_venv}/env.txt - COMMAND ${Python_EXECUTABLE} -m venv ${pytest_venv} - COMMAND ${pytest_executable} -m pip install --disable-pip-version-check cffi setuptools - COMMAND ${pytest_executable} -m pip freeze > ${pytest_venv}/env.txt - BYPRODUCTS ${pytest_executable} - ) # Create c code for cffi extension add_custom_command( --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org