Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #1367 to Garden: Fix find Python3 logic and macOS workflow #1370

Merged
merged 4 commits into from
Jun 24, 2024

Conversation

scpeters
Copy link
Member

@scpeters scpeters commented Feb 2, 2024

Backport

Backport #1367 to Garden. The patch required small modifications since Python3 is required in sdf14 and later but is not required in Garden.

Original commit message:

Fix find Python3 logic and macOS workflow

  • 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

Note to maintainers: Remember to use Rebase-and-Merge.

* 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 <[email protected]>
@scpeters scpeters requested a review from azeey as a code owner February 2, 2024 18:52
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Feb 2, 2024
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.58%. Comparing base (edd5d0b) to head (c934030).
Report is 13 commits behind head on sdf13.

Current head c934030 differs from pull request most recent head 548d4fe

Please upload reports for the commit 548d4fe to get more accurate results.

Additional details and impacted files
@@           Coverage Diff           @@
##            sdf13    #1370   +/-   ##
=======================================
  Coverage   87.58%   87.58%           
=======================================
  Files         128      128           
  Lines       17095    17095           
=======================================
  Hits        14972    14972           
  Misses       2123     2123           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@j-rivero j-rivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to my eyes

Copy link
Contributor

@j-rivero j-rivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor things :)

CMakeLists.txt Outdated Show resolved Hide resolved
# Find python
if (SKIP_PYBIND11)
message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
find_package(Python3 COMPONENTS Interpreter)
Copy link
Contributor

@j-rivero j-rivero Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we are looking for the Interpreter unconditionally. Both cases of SKIP_PYBIND11 look for ir. I see that is being used for embedSdf.py, if it is mandatory could we move it out of the if block to the main CMakeLists.txt course.

If that is valid, if can probably integrate this block with the add_directory(python) a bit below in this file to avoid extra checks in different locations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the changes in this PR, the include(GzPython) line will unconditionally search for the Python interpreter, and then we would separately search for the Development component. I think that can be problematic on systems with multiple versions of python that don't all have the Development component, since it could first find an Interpreter from a non-Development version of Python, and then find a different version of python with the Development component.

So my goal here is to unconditionally search for Python3 one time with the full set of components that are needed, either INTERPRETER or INTERPRETER DEVELOPMENT. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes total sense yes and actually the CMake documentation recommends to do it in an atomic call. Reducing the call to just one outside of the if block and moving the block to merge the add_directory(python) would result in:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa983cee..dd7bf5d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,29 +78,6 @@ 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
   function(find_python_module module)
@@ -159,8 +136,27 @@ if (BUILD_SDF)
   add_subdirectory(sdf)
   add_subdirectory(conf)
   add_subdirectory(doc)
-  if (pybind11_FOUND AND NOT SKIP_PYBIND11)
-    add_subdirectory(python)
+
+  #################################################
+  # Find python
+  find_package(Python3 COMPONENTS Interpreter Development)
+  if (SKIP_PYBIND11)
+    message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
+  else()
+    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}.")
+        add_subdirectory(python)
+      else()
+        GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.")
+        message (STATUS "Searching for pybind11 - not found.")
+      endif()
+    endif()
   endif()
 endif(BUILD_SDF)

whatever you prefer, the atomic call seems to be the most critical point here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid deviation from newer branches, I'm going to keep this as is

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dobule checking: do we prefer to call it with QUITE and add custom STATUS messages below instead of removing the QUIET and the messages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it changes the formatting of the console messages, and I think it's subjective; I'm flexible on this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to you, no strong feeling either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a backport; I'm going to leave this as is to match the behavior in newer branches

Signed-off-by: Steve Peters <[email protected]>
Copy link
Contributor

@j-rivero j-rivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subjective options to take or not. Changes fine.

@scpeters scpeters enabled auto-merge (squash) June 24, 2024 19:12
@scpeters scpeters merged commit b43b83f into sdf13 Jun 24, 2024
10 checks passed
@scpeters scpeters deleted the scpeters/pick_fix_find_python branch June 24, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants