From 9a9e70d5f03859800a6c6acbd58310225a8b63b6 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Wed, 31 Jan 2024 13:34:04 -0800 Subject: [PATCH 1/3] Fix find Python3 logic and macOS workflow (#1367) * Find Python3 with find_package instead of GzPython, adapting the approach from gz-sim. * macos workflow: use brew --prefix, not /usr/local * macos workflow: set Python3_EXECUTABLE cmake var Signed-off-by: Steve Peters --- .github/workflows/macos.yml | 14 +++++------ CMakeLists.txt | 50 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 0842e3e5d..8a4b9f4ca 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -19,11 +19,11 @@ jobs: # Workaround for https://github.com/actions/setup-python/issues/577 - name: Clean up python binaries run: | - rm -f /usr/local/bin/2to3*; - rm -f /usr/local/bin/idle3*; - rm -f /usr/local/bin/pydoc3*; - rm -f /usr/local/bin/python3*; - rm -f /usr/local/bin/python3*-config; + rm -f $(brew --prefix)/bin/2to3*; + rm -f $(brew --prefix)/bin/idle3*; + rm -f $(brew --prefix)/bin/pydoc3*; + rm -f $(brew --prefix)/bin/python3*; + rm -f $(brew --prefix)/bin/python3*-config; - name: Install base dependencies env: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 @@ -50,8 +50,8 @@ jobs: - name: cmake working-directory: build run: | - export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python - cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD + export PYTHONPATH=$PYTHONPATH:$(brew --prefix)/lib/python + cmake .. -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/${PACKAGE}/HEAD -DPython3_EXECUTABLE=$(brew --prefix)/bin/python3 - run: make working-directory: build - run: make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6ce4b9c..fa983ceed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,9 +78,31 @@ if (BUILD_SDF) # available during build time set(GZ_TOOLS_VER 2) + ################################################# + # Find python + if (SKIP_PYBIND11) + message(STATUS "SKIP_PYBIND11 set - disabling python bindings") + find_package(Python3 COMPONENTS Interpreter) + else() + find_package(Python3 COMPONENTS Interpreter Development + ) + if (NOT Python3_Development_FOUND) + GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.") + else() + set(PYBIND11_PYTHON_VERSION 3) + find_package(pybind11 2.4 CONFIG QUIET) + + if (pybind11_FOUND) + message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") + else() + GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.") + message (STATUS "Searching for pybind11 - not found.") + endif() + endif() + endif() + ################################################# # Copied from catkin/cmake/empy.cmake - include(GzPython) function(find_python_module module) # cribbed from http://www.cmake.org/pipermail/cmake/2011-January/041666.html string(TOUPPER ${module} module_upper) @@ -130,30 +152,6 @@ if (BUILD_SDF) gz_find_package(gz-utils2 REQUIRED COMPONENTS cli) set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR}) - ######################################## - # Python interfaces - if (NOT PYTHON3_FOUND) - GZ_BUILD_WARNING("Python is missing: Python interfaces are disabled.") - message (STATUS "Searching for Python - not found.") - else() - message (STATUS "Searching for Python - found version ${Python3_VERSION}.") - - if (SKIP_PYBIND11) - message(STATUS "SKIP_PYBIND11 set - disabling python bindings") - else() - set(PYBIND11_PYTHON_VERSION 3) - find_package(pybind11 2.4 QUIET) - - if (${pybind11_FOUND}) - find_package(Python3 ${GZ_PYTHON_VERSION} REQUIRED COMPONENTS Development) - message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") - else() - GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.") - message (STATUS "Searching for pybind11 - not found.") - endif() - endif() - endif() - gz_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS) gz_create_packages() @@ -162,7 +160,7 @@ if (BUILD_SDF) add_subdirectory(conf) add_subdirectory(doc) if (pybind11_FOUND AND NOT SKIP_PYBIND11) - add_subdirectory(python) + add_subdirectory(python) endif() endif(BUILD_SDF) From 8de28a126ca5ba83b7431187e7714496e07f1168 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 1 Feb 2024 23:39:43 -0800 Subject: [PATCH 2/3] macos.yml: use $(brew --prefix python3) Signed-off-by: Steve Peters --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 8a4b9f4ca..4430c4fef 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -51,7 +51,7 @@ jobs: working-directory: build run: | export PYTHONPATH=$PYTHONPATH:$(brew --prefix)/lib/python - cmake .. -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/${PACKAGE}/HEAD -DPython3_EXECUTABLE=$(brew --prefix)/bin/python3 + cmake .. -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/${PACKAGE}/HEAD -DPython3_EXECUTABLE=$(brew --prefix python3)/bin/python3 - run: make working-directory: build - run: make test From c9340301f156b6dba64c94b5adb67f6f9a3a19c8 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 8 Feb 2024 15:02:52 -0800 Subject: [PATCH 3/3] one-line find_package call Signed-off-by: Steve Peters --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa983ceed..e2173e6ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,8 +84,7 @@ if (BUILD_SDF) message(STATUS "SKIP_PYBIND11 set - disabling python bindings") find_package(Python3 COMPONENTS Interpreter) else() - find_package(Python3 COMPONENTS Interpreter Development - ) + find_package(Python3 COMPONENTS Interpreter Development) if (NOT Python3_Development_FOUND) GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.") else()