Skip to content

Commit

Permalink
Merge pull request #1135 from VincentRouvreau/cmake_improvement_with_…
Browse files Browse the repository at this point in the history
…importlib_metadata

Cmake improvement with importlib metadata
  • Loading branch information
VincentRouvreau authored Sep 26, 2024
2 parents d9b15c5 + 9fbea63 commit 7c3e328
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .github/next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Below is a list of changes:

- Installation
- CMake ≥ 3.15 is now required (was ≥ 3.8).
- Python ≥ 3.8 is now required (was ≥ 3.5), because of `importlib.metadata`.

- Miscellaneous
- The [list of bugs that were solved](https://github.com/GUDHI/gudhi-devel/issues?q=label%3A3.11.0+is%3Aclosed) is available on GitHub.
Expand All @@ -29,7 +30,7 @@ However, there are still GPL dependencies for many modules. We invite you to che

We kindly ask users to cite the GUDHI library as appropriately as possible in their papers, and to mention the use of the GUDHI library on the web pages of their projects using GUDHI and provide us with links to these web pages.

We provide [bibtex entries](https://gudhi.inria.fr/doc/latest/_citation.html) for the modules of the User and Reference Manual, as well as for publications directly related to the GUDHI library.
We provide [bibtex entries](https://gudhi.inria.fr/doc/latest/_citation.html) for the modules of the User and Reference Manual, as well as for publications directly related to the GUDHI library.

Feel free to [contact us](https://gudhi.inria.fr/contact/) in case you have any questions or remarks.

Expand Down
36 changes: 11 additions & 25 deletions src/cmake/modules/GUDHI_third_party_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -167,46 +168,31 @@ 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")
# Specific case for PyKeops on Windows where import fails because it uses fcntl (not available on Windows)
if (NOT WIN32)
find_python_module("pykeops")
endif()
endif()


if(NOT GUDHI_PYTHON_PATH)
message(FATAL_ERROR "ERROR: GUDHI_PYTHON_PATH is not valid.")
endif(NOT GUDHI_PYTHON_PATH)
Expand Down
36 changes: 17 additions & 19 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,18 @@ if(SCIPY_FOUND)
else()
disable_python_documentation("scipy")
endif()
if(SKLEARN_FOUND)
add_gudhi_debug_info("Scikit-learn version ${SKLEARN_VERSION}")
if(SCIKIT-LEARN_FOUND)
add_gudhi_debug_info("Scikit-learn version ${SCIKIT-LEARN_VERSION}")
else()
disable_python_documentation("sklearn")
disable_python_documentation("scikit-learn")
endif()
if(OT_FOUND)
add_gudhi_debug_info("POT version ${OT_VERSION}")
if(POT_FOUND)
add_gudhi_debug_info("POT version ${POT_VERSION}")
else()
disable_python_documentation("ot")
endif()
if(HNSWLIB_FOUND)
# Does not have a version number...
add_gudhi_debug_info("HNSWlib found")
add_gudhi_debug_info("HNSWlib version ${HNSWLIB_VERSION}")
endif()
if(TORCH_FOUND)
add_gudhi_debug_info("PyTorch version ${TORCH_VERSION}")
Expand Down Expand Up @@ -175,8 +174,7 @@ else()
disable_python_documentation("pydata_sphinx_theme")
endif()
if(SPHINXCONTRIB.BIBTEX_FOUND)
# Does not have a version number...
add_gudhi_debug_info("sphinxcontrib-bibtex found")
add_gudhi_debug_info("sphinxcontrib-bibtex version ${SPHINXCONTRIB.BIBTEX_VERSION}")
else()
disable_python_documentation("sphinxcontrib-bibtex")
endif()
Expand Down Expand Up @@ -461,7 +459,7 @@ add_test(NAME random_cubical_complex_persistence_example_py_test
add_gudhi_py_test(test_cubical_complex)

# Datasets are fetched for these tests
if(SKLEARN_FOUND AND WITH_GUDHI_REMOTE_TEST)
if(SCIKIT-LEARN_FOUND AND WITH_GUDHI_REMOTE_TEST)
add_gudhi_py_test(test_sklearn_cubical_persistence)

add_test(NAME cubical_complex_sklearn_itf_py_test
Expand Down Expand Up @@ -590,7 +588,7 @@ add_test(NAME rips_complex_from_points_example_py_test

add_gudhi_py_test(test_rips_complex)

if(SKLEARN_FOUND)
if(SCIKIT-LEARN_FOUND)
# test_sklearn_rips_persistence is using gudhi.datasets.generators
if (TARGET CGAL::CGAL AND TARGET Eigen3::Eigen)
add_gudhi_py_test(test_sklearn_rips_persistence)
Expand Down Expand Up @@ -636,7 +634,7 @@ add_gudhi_py_test(test_reader_utils)
add_gudhi_py_test(test_off)

# Wasserstein
if(OT_FOUND)
if(POT_FOUND)
# EagerPy dependency because of enable_autodiff=True
if(EAGERPY_FOUND)
add_gudhi_py_test(test_wasserstein_distance)
Expand All @@ -648,7 +646,7 @@ if(OT_FOUND)
endif()

# Representations
if(SKLEARN_FOUND AND MATPLOTLIB_FOUND AND OT_FOUND AND TARGET CGAL::CGAL)
if(SCIKIT-LEARN_FOUND AND MATPLOTLIB_FOUND AND POT_FOUND AND TARGET CGAL::CGAL)
add_gudhi_py_test(test_representations)
endif()

Expand All @@ -658,31 +656,31 @@ if(TENSORFLOW_FOUND)
endif()

# Perslay
if(TENSORFLOW_FOUND AND SKLEARN_FOUND)
if(TENSORFLOW_FOUND AND SCIKIT-LEARN_FOUND)
add_gudhi_py_test(test_perslay)
endif()

# Betti curves
if(SKLEARN_FOUND AND SCIPY_FOUND)
if(SCIKIT-LEARN_FOUND AND SCIPY_FOUND)
add_gudhi_py_test(test_betti_curve_representations)
endif()

# Representations preprocessing
if(SKLEARN_FOUND)
if(SCIKIT-LEARN_FOUND)
add_gudhi_py_test(test_representations_preprocessing)
endif()

# Time Delay
add_gudhi_py_test(test_time_delay)

# DTM
if(SCIPY_FOUND AND SKLEARN_FOUND AND TORCH_FOUND AND HNSWLIB_FOUND AND PYKEOPS_FOUND AND EAGERPY_FOUND)
if(SCIPY_FOUND AND SCIKIT-LEARN_FOUND AND TORCH_FOUND AND HNSWLIB_FOUND AND PYKEOPS_FOUND AND EAGERPY_FOUND)
add_gudhi_py_test(test_knn)
add_gudhi_py_test(test_dtm)
endif()

# Tomato
if(SCIPY_FOUND AND SKLEARN_FOUND)
if(SCIPY_FOUND AND SCIKIT-LEARN_FOUND)
add_gudhi_py_test(test_tomato)
endif()

Expand All @@ -697,7 +695,7 @@ if(SCIPY_FOUND)
endif()

# Cover complex
if(SKLEARN_FOUND)
if(SCIKIT-LEARN_FOUND)
add_gudhi_py_test(test_cover_complex)
endif()

Expand Down
54 changes: 28 additions & 26 deletions src/python/doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ there.

The library uses c++17 and requires `Boost <https://www.boost.org/>`_ :math:`\geq` 1.71.0,
`CMake <https://www.cmake.org/>`_ :math:`\geq` 3.15,
Python :math:`\geq` 3.5, `NumPy <http://numpy.org>`_ :math:`\geq` 1.15.0, `Cython <https://www.cython.org/>`_
Python :math:`\geq` 3.8, `NumPy <http://numpy.org>`_ :math:`\geq` 1.15.0, `Cython <https://www.cython.org/>`_
:math:`\geq` 0.27 and `pybind11 <https://github.com/pybind/pybind11>`_ to compile the GUDHI Python module.
It is a multi-platform library and compiles on Linux, Mac OSX and Visual Studio 2017 or later.

Expand Down Expand Up @@ -145,18 +145,18 @@ You shall have something like:

.. code-block:: none
Pybind11 version 2.8.1
Pybind11 version 2.8.1
Python version 3.7.12
Cython version 0.29.25
Numpy version 1.21.4
Cython version 0.29.25
Numpy version 1.21.4
Boost version 1.77.0
+ Installed modules are: off_utils;simplex_tree;rips_complex;cubical_complex;periodic_cubical_complex;
persistence_graphical_tools;reader_utils;witness_complex;strong_witness_complex;
+ Missing modules are: bottleneck;nerve_gic;subsampling;tangential_complex;alpha_complex;euclidean_witness_complex;
euclidean_strong_witness_complex;
Here, you can see that the modules that need CGAL are missing, because CGAL is not installed.
:code:`persistence_graphical_tools` is installed, but
:code:`persistence_graphical_tools` is installed, but
`its functions <https://gudhi.inria.fr/python/latest/persistence_graphical_tools_ref.html>`_ will produce an error as
matplotlib is not available.
Unitary tests cannot be run as pytest is missing.
Expand All @@ -165,26 +165,28 @@ A complete configuration would be :

.. code-block:: none
Pybind11 version 2.8.1
Python version 3.9.7
Cython version 0.29.24
Pytest version 6.2.5
Matplotlib version 3.5.0
Numpy version 1.21.4
Scipy version 1.7.3
Scikit-learn version 1.0.1
POT version 0.8.0
HNSWlib found
PyKeOps version [pyKeOps]: 2.1
EagerPy version 0.30.0
TensorFlow version 2.7.0
Sphinx version 4.3.0
Sphinx-paramlinks version 0.5.2
pydata_sphinx_theme version 0.13.1
NetworkX version 3.0
Python version 3.11.9
Pybind11 version 2.12.0
Cython version 3.0.10
Numpy version 1.24.3
Pytest version 8.2.1
Matplotlib version 3.9.0
Scipy version 1.13.1
Scikit-learn version 1.3.2
POT version 0.9.4
HNSWlib version 0.8.0
PyTorch version 2.3.0
PyKeOps version 2.2.3
EagerPy version 0.30.0
TensorFlow version 2.13.1
Sphinx version 7.3.7
Sphinx-paramlinks version 0.6.0
pydata_sphinx_theme version 0.15.2
sphinxcontrib-bibtex version 2.6.2
NetworkX version 3.3
Eigen3 version 3.4.0
Boost version 1.74.0
CGAL version 5.3
Boost version 1.84.0
CGAL header only version 5.6.1
GMP_LIBRARIES = /usr/lib/x86_64-linux-gnu/libgmp.so
GMPXX_LIBRARIES = /usr/lib/x86_64-linux-gnu/libgmpxx.so
MPFR_LIBRARIES = /usr/lib/x86_64-linux-gnu/libmpfr.so
Expand All @@ -194,7 +196,7 @@ A complete configuration would be :
+ Installed modules are: bottleneck;off_utils;simplex_tree;rips_complex;cubical_complex;periodic_cubical_complex;
persistence_graphical_tools;reader_utils;witness_complex;strong_witness_complex;nerve_gic;subsampling;
tangential_complex;alpha_complex;euclidean_witness_complex;euclidean_strong_witness_complex;
+ Missing modules are:
+ Missing modules are:
Documentation
Expand Down Expand Up @@ -422,7 +424,7 @@ TensorFlow
requires `TensorFlow <https://www.tensorflow.org/>`_.
The :doc:`cubical complex </cubical_complex_tflow_itf_ref>`, :doc:`simplex tree </ls_simplex_tree_tflow_itf_ref>`
and :doc:`Rips complex </rips_complex_tflow_itf_ref>` modules require `TensorFlow`_
for incorporating them in neural nets.
for incorporating them in neural nets.

`TensorFlow`_ is also used in some automatic differentiation tests.

Expand Down
2 changes: 1 addition & 1 deletion src/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ setup(
long_description_content_type='text/x-rst',
long_description='@GUDHI_LONG_DESCRIPTION@',
ext_modules = ext_modules,
python_requires='>=3.5.0',
python_requires='>=3.8.0',
install_requires = ['numpy >= 1.15.0',],
package_data={"": ["*.dll"], },
)

0 comments on commit 7c3e328

Please sign in to comment.