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

Use find_package(Python) instead of PythonInterp #1007

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

VincentRouvreau
Copy link
Contributor

@VincentRouvreau VincentRouvreau commented Nov 29, 2023

Modification taken from #151
Fix #139
CMake 3.12 is now 5 years old 3.15 is now 4 years old (july 2019), so it should be ok for every one.
CMake 3.15 is required for cmake_policy(SET CMP0094 NEW)
CMake 3.16 (nov 2019) is required if the user wants to specify a python interpreter (cmake -DPython_EXECUTABLE=/custom/path/to/python3 ...)

@@ -45,7 +45,7 @@ jobs:
python --version
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DPython_ADDITIONAL_VERSIONS=3 ..
cmake -DCMAKE_BUILD_TYPE=Release -DPython_EXECUTABLE=$(which python) ..
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I precised it on 7e33f42 because macosx-11.7-universal2 has several python installation available and cmake was not finding the correct one, cf. https://github.com/GUDHI/gudhi-devel/actions/runs/7030598162/job/19130456933#step:5:60
When I precise Python_EXECUTABLE, the error is no more.
I wanted to do the same for Windows, but my batch command seems not correct, WIP

Copy link
Member

Choose a reason for hiding this comment

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

I guess my question is whether users are likely to be hindered by this change in our CMake scripts (just like we were affected in our CI), and how we could help. For instance, if cmake happily stops when it finds a version of python that doesn't have the development parts, we could tell find_package that we require components Interpreter and Development.Module (and possibly NumPy) so hopefully it keeps looking for another python in that case. There are also several options that can affect the strategy:

  • setting policy CMP0094 to NEW changes Python_FIND_STRATEGY a bit
  • Python_FIND_UNVERSIONED_NAMES can be set to FIRST if we prefer python to python3.X

There are also Python_FIND_REGISTRY (windows) and Python_FIND_FRAMEWORK (macos), but they don't look like things we should force on users. We could use them in CI, but in CI specifying the executable (as you did) is probably more reliable.

By the way, does Python_EXECUTABLE need a full path, or does -DPython_EXECUTABLE=python work?

Copy link
Member

Choose a reason for hiding this comment

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

By the way, does Python_EXECUTABLE need a full path, or does -DPython_EXECUTABLE=python work?

https://cmake.org/cmake/help/latest/module/FindPython.html says

Note: All paths must be absolute. Any artifact specified with a relative path will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't notice it the first time I wrote the PR, but setting policy CMP0094 to NEW seems promising as it is using the python interpreter from my conda environment instead of the one from my system. It worth it to test it, even if it requires cmake 3.15 (july 2019). I rewrite some python cmake horrors and I will give it a try

@VincentRouvreau VincentRouvreau marked this pull request as draft December 11, 2023 09:38
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.

FindPythonInterp deprecated
2 participants