Skip to content

Commit

Permalink
Try to make sure we use the host's Python interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 1, 2023
1 parent 55ba2ae commit 815c2a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ elseif(WIN32)
find_package(VLD)
endif()

find_program(HOST_Python3_EXECUTABLE python3 DOC "Path to (host) Python 3 Interpreter")

include(PythonUtils)
include(PlasmaTargets)

Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ python_test_modules(
REQUIREMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/external/requirements.txt"
)

cmake_dependent_option(PLASMA_BUILD_RESOURCE_DAT "Do we want to build resource.dat?" ON "cairosvg_FOUND AND PIL_FOUND" OFF)
cmake_dependent_option(PLASMA_BUILD_RESOURCE_DAT "Do we want to build resource.dat?" ON "cairosvg_FOUND AND PIL_FOUND AND HOST_Python3_EXECUTABLE" OFF)
cmake_dependent_option(RESOURCE_OPTIMIZE "Optimize the images in resource.dat" ON "PLASMA_BUILD_RESOURCE_DAT AND PNGCRUSH_EXECUTABLE" OFF)
cmake_dependent_option(RESOURCE_BRUTE "Allow pngcrush brute-force optimization" OFF "PLASMA_BUILD_RESOURCE_DAT AND PNGCRUSH_EXECUTABLE" OFF)

Expand All @@ -37,7 +37,7 @@ if(PLASMA_BUILD_RESOURCE_DAT)

add_custom_command(
OUTPUT ${external_DAT}
COMMAND "${Python3_EXECUTABLE}"
COMMAND "${HOST_Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/external/makeres.py"
--render --package
${OPTIMIZE_ARGUMENT}
Expand Down
16 changes: 10 additions & 6 deletions cmake/PythonUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ function(python_test_modules)
message(FATAL_ERROR "python_test_modules() must be given a list of MODULES")
endif()

if(NOT HOST_Python3_EXECUTABLE)
message(WARNING "No host Python interpreter")
endif()

# Optional: attempt to install modules from pip before checking their existence.
if(ENABLE_PIP_INSTALL AND NOT _ptm_DONT_INSTALL)
if(HOST_Python3_EXECUTABLE AND ENABLE_PIP_INSTALL AND NOT _ptm_DONT_INSTALL)
if(NOT _PLASMA_ENSUREPIP_DONE)
message(STATUS "Bootstrapping pip...")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m ensurepip
COMMAND "${HOST_Python3_EXECUTABLE}" -m ensurepip
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
Expand All @@ -25,14 +29,14 @@ function(python_test_modules)
if(_ptm_REQUIREMENTS_FILE)
message(STATUS "Installing Python modules from: ${_ptm_REQUIREMENTS_FILE}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install -r "${_ptm_REQUIREMENTS_FILE}"
COMMAND "${HOST_Python3_EXECUTABLE}" -m pip install -r "${_ptm_REQUIREMENTS_FILE}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
else()
message(STATUS "Installing Python modules: ${_ptm_MODULES}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pip install ${_ptm_MODULES}
COMMAND "${HOST_Python3_EXECUTABLE}" -m pip install ${_ptm_MODULES}
OUTPUT_QUIET ERROR_QUIET
)
endif()
Expand All @@ -43,9 +47,9 @@ function(python_test_modules)
endif()

foreach(_module_NAME IN LISTS _ptm_MODULES)
if(Python3_EXECUTABLE)
if(HOST_Python3_EXECUTABLE)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "import ${_module_NAME}"
COMMAND "${HOST_Python3_EXECUTABLE}" -c "import ${_module_NAME}"
RESULT_VARIABLE RETURNCODE
OUTPUT_QUIET ERROR_QUIET
)
Expand Down

0 comments on commit 815c2a4

Please sign in to comment.