find_package(LibStdCpp)
+# Python is first referenced in gmxVersionInfo, so we perform the search early
+# to find a suitable installation for all components.
+include(gmxPythonDiscovery)
# Set up common version variables, as well as general information about
# the build tree (whether the build is from a source package or from a git
# repository). Also declares a few functions that will be used for generating
mark_as_advanced(GMX_PYTHON_PACKAGE)
if (NOT GMX_BUILD_MDRUN_ONLY)
- # Note: Though only documented as an output variable, PYTHON_EXECUTABLE is
- # also effective as a CMake input variable to effectively hint the location
- # of the Python interpreter. This may be helpful in environments with both
- # Python 2 and Python 3 on the default PATH.
- # Ref: https://cmake.org/cmake/help/latest/module/FindPythonInterp.html
- if(FIND_PACKAGE_MESSAGE_DETAILS_PythonInterp)
- # Keep quiet on subsequent runs of cmake
- set(PythonInterp_FIND_QUIETLY ON)
- endif()
- # Older CMake versions might not search for Python newer than 3.7.
- set(Python_ADDITIONAL_VERSIONS 3.8)
- if(GMX_PYTHON_PACKAGE)
- find_package(PythonInterp 3.6 REQUIRED)
- # Note: PythonLibs will be found later by pybind11.
- # TODO: (Issue #2998) When CMake >= 3.12 is required, update detection.
- # I.e. find_package(Python3 3.6 COMPONENTS Interpreter Development REQUIRED)
- else()
- find_package(PythonInterp 3.6)
- endif()
find_package(ImageMagick QUIET COMPONENTS convert)
include(gmxTestImageMagick)
GMX_TEST_IMAGEMAGICK(IMAGE_CONVERT_POSSIBLE)
# Adapted from code posted on cmake-users by Mark Moll (the execute_process()
# call remains, but other things have been rewritten for nicer behavior).
-find_package(PythonInterp 3.6)
function (find_python_module module)
string(TOUPPER ${module} _module_upper)
--- /dev/null
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2020, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+# Perform Python installation discovery early and in one place, for consistency.
+#
+# Note: If necessary, the Python location can be hinted with Python3_ROOT_DIR
+# For additional parameters affecting Python installation discovery, see
+# https://cmake.org/cmake/help/latest/module/FindPython3.html#hints
+if(FIND_PACKAGE_MESSAGE_DETAILS_Python3)
+ # Keep quiet on subsequent runs of cmake
+ set(Python3_FIND_QUIETLY ON)
+ set(PythonInterp_FIND_QUIETLY ON)
+endif()
+# Older CMake versions might not search for Python newer than 3.7.
+set(Python_ADDITIONAL_VERSIONS 3.8)
+# We advocate using Python venvs to manage package availability, so by default
+# we want to preferentially discover user-space software.
+set(Python3_FIND_REGISTRY LAST)
+# Make package discovery consistent with Unix behavior and our documented
+# suggestions for installing dependencies.
+set(CMAKE_FIND_FRAMEWORK LAST)
+if(GMX_PYTHON_PACKAGE)
+ find_package(Python3 3.6 COMPONENTS Interpreter Development)
+ if (NOT Python3_FOUND OR NOT Python3_Development_FOUND)
+ message(FATAL_ERROR "Could not locate Python development requirements. \
+ Provide appropriate CMake hints or set GMX_PYTHON_PACKAGE=OFF")
+ endif ()
+else()
+ find_package(Python3 3.6 COMPONENTS Interpreter)
+endif()
+# Other components, such as pybind and googletest, may expect the
+# PYTHON_EXECUTABLE variable from pre-3.12 FindPythonInterp.cmake.
+if (Python3_Interpreter_FOUND)
+ set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Location hint for Python interpreter.")
+endif ()
+# We've already generated all of the output we need, even though other subcomponents
+# may call find_package(PythonInterp) later on.
+set(Python3_FIND_QUIETLY ON)
+set(PythonInterp_FIND_QUIETLY ON)
list(APPEND SET_OF_DIRECTORIES_TO_CHECKSUM "${PROJECT_SOURCE_DIR}/python_packaging")
# Due to the limitations for passing a list as arguments, we make the directories a string here
string(REPLACE ";" ":" DIRECTORIES_TO_CHECKSUM_STRING "${SET_OF_DIRECTORIES_TO_CHECKSUM}")
-# Try to find python for the checksumming script
-set(PythonInterp_FIND_QUIETLY ON)
-find_package(PythonInterp 3.6)
# Rules to create the VersionInfo.cmake file.
# For git info, the sequence is:
# not been tampered with.
# Note: The RUN_ALWAYS here is to regenerate the hash file only, it does not
# mean that the target is run in all builds
-if (PYTHONINTERP_FOUND)
+if (PYTHON_EXECUTABLE)
gmx_add_custom_output_target(reference_checksum RUN_ALWAYS
OUTPUT ${CHECKSUM_FILE}
COMMAND ${PYTHON_EXECUTABLE}
set(HTML_BUILD_WARNINGS)
# Next, turn it off if any of the preconditions are unsatisified
-if (NOT PythonInterp_FOUND)
+if (NOT Python3_Interpreter_FOUND)
set(HTML_BUILD_IS_POSSIBLE OFF)
set(HTML_BUILD_NOT_POSSIBLE_REASON "Python is required")
elseif (NOT SPHINX_FOUND)
mark_as_advanced(GMX_COMPACT_DOXYGEN)
set(USE_PYTHON_SCRIPTS OFF)
-if (PYTHONINTERP_FOUND)
+if (PYTHON_EXECUTABLE)
set(USE_PYTHON_SCRIPTS ON)
endif()
Sometimes the build environment can choose a different Python interpreter than
the one you intended.
-You can set the ``PYTHON_EXECUTABLE`` CMake variable to explicitly choose the
-Python interpreter for your chosen installation.
-For example: ``-DPYTHON_EXECUTABLE=\`which python\```
+You can set the ``Python3_ROOT`` or ``CMAKE_PREFIX_PATH`` CMake variable to
+explicitly choose the Python installation or *venv* directory.
+
+If you use pyenv or pyenv-virtualenv to dynamically manage your Python version,
+you can help identify a particular version with ``pyenv version-name`` and the
+directory with ``pyenv prefix {version}``. For example::
+
+ -DPython3_ROOT=$(pyenv prefix $(pyenv version-name))
Docker web server
-----------------
Portability
^^^^^^^^^^^
-Supported Python versions
-"""""""""""""""""""""""""
+Python environment
+""""""""""""""""""
Where Python is required,
`CPython <https://www.python.org>`__ versions 3.6 to 3.8 are supported.
+CMake now detects Python using
+`FindPython3 <https://cmake.org/cmake/help/v3.13/module/FindPython3.html>`__.
+If you previously used ``PYTHON_EXECUTABLE`` to hint the location of the Python
+interpreter, you should instead specify the Python "root" or "prefix" path
+(the directory containing ``./bin/python3``) with CMake variable
+``Python3_ROOT`` or ``CMAKE_PREFIX_PATH``. As other infrastructure evolves,
+``PYTHON_EXECUTABLE`` may cease to have the desired effect without warning.
+
.. Note to developers!
Please use """"""" to underline the individual entries for fixed issues in the subfolders,
otherwise the formatting on the webpage is messed up.
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2019, by the GROMACS development team, led by
+# Copyright (c) 2019,2020, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
# (system or user) GROMACS installation and (user) Python environment. For a
# system-wide Python environment, the package needs to be built and installed
# (to the ``site-packages`` directory) for each supported Python interpreter.
-# ``setup.py`` can just be invoked with different Python interpreters. We can
-# add CMake infrastructure to allow multiple/repeated PYTHON_EXECUTABLE
-# specification at the GROMACS project level if such a use case is important to
-# HPC site administrators or Linux distribution packagers.
+# ``setup.py`` can just be invoked with different Python interpreters.
#
# To drive the packaging of a Python package distribution archive
# by a higher-level CMake configuration, a CMakeLists.txt file at this level would
# End copied from regression tests.
#
- if (NOT PYTHONINTERP_FOUND)
+ if (NOT Python3_Interpreter_FOUND)
message(FATAL_ERROR
"Python not found. Physical validation requires python. \
- Install python, set PYTHON_EXECUTABLE to a valid python location, \
+ Install python, set Python3_ROOT_DIR or PYTHON_EXECUTABLE to a valid location, \
or set GMX_PHYSICAL_VALIDATION=OFF to disable the physical validation tests.")
endif()
#