-
Notifications
You must be signed in to change notification settings - Fork 67
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
Cmake improvement with importlib metadata #1135
Changes from 3 commits
8d4fe2b
7b6d033
848d853
b4694d9
9fbea63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,8 +145,9 @@ if (WITH_GUDHI_PYTHON) | |
# returns ${PYTHON_MODULE_NAME_UP}_VERSION and ${PYTHON_MODULE_NAME_UP}_FOUND | ||
function( find_python_module PYTHON_MODULE_NAME ) | ||
string(TOUPPER ${PYTHON_MODULE_NAME} PYTHON_MODULE_NAME_UP) | ||
# Modify tracebacklimit as the exception is quite verbose when module is not found | ||
execute_process( | ||
COMMAND ${Python_EXECUTABLE} -c "import ${PYTHON_MODULE_NAME}; print(${PYTHON_MODULE_NAME}.__version__)" | ||
COMMAND ${Python_EXECUTABLE} -c "import sys; sys.tracebacklimit = 0; from importlib.metadata import version; print(version('${PYTHON_MODULE_NAME}'))" | ||
RESULT_VARIABLE PYTHON_MODULE_RESULT | ||
OUTPUT_VARIABLE PYTHON_MODULE_VERSION | ||
ERROR_VARIABLE PYTHON_MODULE_ERROR) | ||
|
@@ -167,46 +168,37 @@ if (WITH_GUDHI_PYTHON) | |
endif() | ||
endfunction( find_python_module ) | ||
|
||
# For modules that do not define module.__version__ | ||
function( find_python_module_no_version PYTHON_MODULE_NAME ) | ||
string(TOUPPER ${PYTHON_MODULE_NAME} PYTHON_MODULE_NAME_UP) | ||
execute_process( | ||
COMMAND ${Python_EXECUTABLE} -c "import ${PYTHON_MODULE_NAME}" | ||
RESULT_VARIABLE PYTHON_MODULE_RESULT | ||
ERROR_VARIABLE PYTHON_MODULE_ERROR) | ||
if(PYTHON_MODULE_RESULT EQUAL 0) | ||
# Remove carriage return | ||
message ("++ Python module ${PYTHON_MODULE_NAME} found") | ||
set(${PYTHON_MODULE_NAME_UP}_FOUND TRUE PARENT_SCOPE) | ||
else() | ||
message ("PYTHON_MODULE_NAME = ${PYTHON_MODULE_NAME} | ||
- PYTHON_MODULE_RESULT = ${PYTHON_MODULE_RESULT} | ||
- PYTHON_MODULE_ERROR = ${PYTHON_MODULE_ERROR}") | ||
set(${PYTHON_MODULE_NAME_UP}_FOUND FALSE PARENT_SCOPE) | ||
endif() | ||
endfunction( find_python_module_no_version ) | ||
|
||
if( TARGET Python::Interpreter ) | ||
find_python_module("cython") | ||
find_python_module("pytest") | ||
find_python_module("matplotlib") | ||
find_python_module("numpy") | ||
find_python_module("scipy") | ||
find_python_module("sphinx") | ||
find_python_module("sklearn") | ||
find_python_module("ot") | ||
find_python_module("scikit-learn") | ||
find_python_module("POT") | ||
find_python_module("pybind11") | ||
find_python_module("torch") | ||
find_python_module("pykeops") | ||
find_python_module("eagerpy") | ||
find_python_module_no_version("hnswlib") | ||
find_python_module("hnswlib") | ||
find_python_module("tensorflow") | ||
find_python_module("sphinx_paramlinks") | ||
find_python_module("pydata_sphinx_theme") | ||
find_python_module_no_version("sphinxcontrib.bibtex") | ||
find_python_module("sphinxcontrib.bibtex") | ||
find_python_module("networkx") | ||
endif() | ||
|
||
# Specific case for PyKeops that can be imported on Windows, but fails because it uses fcntl (not available on Windows) | ||
# Also fcntl has no metadata, so find_python_module does not work | ||
# "import fcntl" is about 1 sec. faster than "import pykeops" | ||
execute_process( | ||
COMMAND ${Python_EXECUTABLE} -c "import fcntl" | ||
RESULT_VARIABLE FCNTL_IMPORT_MODULE_RESULT | ||
OUTPUT_VARIABLE FCNTL_IMPORT_MODULE_OUPUT) | ||
if(FCNTL_IMPORT_MODULE_RESULT EQUAL 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that better than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you are right. I wanted to do something smarter, like "the day fcntl will be available on windows, pykeops will work on windows", but that was not that smart... |
||
find_python_module("pykeops") | ||
endif() | ||
|
||
if(NOT GUDHI_PYTHON_PATH) | ||
message(FATAL_ERROR "ERROR: GUDHI_PYTHON_PATH is not valid.") | ||
endif(NOT GUDHI_PYTHON_PATH) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the use of type hints also requires 3.8? I don't remember.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python 3.5 for type hints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Note that they added new type hinting possibilities with almost every release, so it is hard to be sure we aren't using modern things that were absent in older releases we are not testing anymore. Anyway, let's ignore this.