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

Update deprecated FindPython #4782

Closed
wants to merge 2 commits into from
Closed

Conversation

infinitesnow
Copy link

CMake 2.27 removes support for deprecated FindPython scripts.

In case CMake is custom built/installed in /usr/local, it seems to pick up the version of FindPython from the /usr/share folder. This causes issues when, for example, using a custom built installation of Python in /usr/local: if the version is more recent than what's listed in the system CMake script, it's not picked up.

Use the new version of the script, so Python is picked up correctly.

Description

Suggested changelog entry:

CMake 2.27 removes support for deprecated FindPython scripts.

In case CMake is custom built/installed in /usr/local, it seems to pick
up the version of FindPython from the /usr/share folder. This causes
issues when, for example, using a custom built installation of
Python in `/usr/local`: if the version is more recent than what's listed
in the system CMake script, it's not picked up.

Use the new version of the script, so Python is picked up correctly.
@infinitesnow
Copy link
Author

CMake 3.5 on Ubuntu 20 seems to be missing FindPython.

All other failures are missing pytest, which I believe to be unrelated to my patch.

@henryiii
Copy link
Collaborator

henryiii commented Aug 7, 2023

FindPython was added in 3.15, and we still have to support 3.10 or so. There are several options already implemented:

  • Set PYBIND11_FINDPYTHON before finding pybind11.
  • Run FindPython before finding pybind11
  • Set your maximum or minimum version of CMake to 3.27, then pybind11 will switch to using FindPython by default. (pybind11 2.11+ only)

Anything else would not be backward compatible and would break a lot of code.

For the bug you are seeing, there might need to be a fix, but we can't break thousands of existing packages doing it. :)

@@ -16,6 +16,9 @@ else()
cmake_policy(VERSION 3.26)
endif()

# Include Python headers from FindPython
include_directories(${Python_INCLUDE_DIRS})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should happen via targets already. You shouldn't need to use targetless commands like this in modern CMake.

@henryiii
Copy link
Collaborator

henryiii commented Aug 7, 2023

If you find a way to fix (or reproduce via docker) the /usr/local vs. /usr bug, we can discuss that. But we can't break existing packages that are not opting into 3.15+ only FindPython mode (technically, 3.18+ if you need Development.Module, which you have to do to build manylinux wheels or for PyPy support).

@henryiii henryiii closed this Aug 7, 2023
@infinitesnow
Copy link
Author

I see. I encountered this bug while working at my previous company, but I don't have access to that repository anymore so unfortunately I'm unable to reproduce. Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants