<commit_before># Copyright (C) 1995-2019, <NAME> and <NAME>.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

#---Check for Python installation-------------------------------------------------------

message(STATUS "Looking for Python")

if(pyroot_experimental)
  unset(PYTHON_INCLUDE_DIR CACHE)
  unset(PYTHON_LIBRARY CACHE)
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
  # - Check if the PYTHON_EXECUTABLE deprecated variable was passed by the
  # user; if so, check weather it points to Python 2 or 3 and set the
  # appropriate Python{X}_EXECUTABLE variable
  # - Look for Python3 and set the deprecated variables to the ones set
  # automatically by find_package(Python3 ...)
  # - Look for Python2 and set the deprecated variables to the ones set
  # automatically by find_package(Python2 ...) ONLY IF PYTHON3 WASN'T FOUND
  if(PYTHON_EXECUTABLE)
    execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(sys.version_info[0])"
                    OUTPUT_VARIABLE PYTHON_PREFER_VERSION
                    ERROR_VARIABLE PYTHON_PREFER_VERSION_ERR)
    if(PYTHON_PREFER_VERSION_ERR)
      message(WARNING "Unable to determine version of ${PYTHON_EXECUTABLE}: ${PYTHON_PREFER_VERSION_ERR}")
    endif()
    string(STRIP "${PYTHON_PREFER_VERSION}" PYTHON_PREFER_VERSION)
    set(Python${PYTHON_PREFER_VERSION}_EXECUTABLE "${PYTHON_EXECUTABLE}")
  endif()

  find_package(Python3 COMPONENTS Interpreter Development NumPy)
  if(Python3_Development_FOUND)
    set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}" CACHE INTERNAL "" FORCE)
    set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
    set(PYTHON_LIBRARIES "${Python3_LIBRARIES}" CACHE INTERNAL "" FORCE)
    set(PYTHON_VERSION_STRING "${Python3_VERSION}" CACHE INTERNAL "" FORCE)
    set(PYTHON_VERSION_MAJOR "${Python3_VERSION_MAJOR}" CACHE INTERNAL "" FORCE)
    set(PYTHON_VERSION_MINOR "${Python3_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
    set(PYTHON_UNDER_VERSION_STRING "${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}")
    set(NUMPY_FOUND ${Python3_NumPy_FOUND} CACHE INTERNAL "" FORCE)
    set(NUMPY_INCLUDE_DIRS "${Python3_NumPy_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
  endif()

  find_package(Python2 COMPONENTS Interpreter Development NumPy)
  if(DEFINED Python2_VERSION AND "${Python2_VERSION}" VERSION_LESS "2.7")
    message(WARNING "Ignoring Python2 installation: unsupported version ${Python2_VERSION} (version>=2.7 required)")
  endif()
  if(Python2_Development_FOUND AND "${Python2_VERSION}" VERSION_GREATER_EQUAL "2.7")
    if(NOT Python3_Development_FOUND)
      # Only Python2 was found, set as main
      set(PYTHON_EXECUTABLE "${Python2_EXECUTABLE}" CACHE INTERNAL "" FORCE)
      set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
      set(PYTHON_LIBRARIES "${Python2_LIBRARIES}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_STRING "${Python2_VERSION}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_UNDER_VERSION_STRING "${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}")
      set(NUMPY_FOUND ${Python2_NumPy_FOUND} CACHE INTERNAL "" FORCE)
      set(NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
    else()
      # Both Python3 and 2 found, set 2 as 'other'
      set(OTHER_PYTHON_EXECUTABLE "${Python2_EXECUTABLE}")
      set(OTHER_PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}")
      set(OTHER_PYTHON_LIBRARIES "${Python2_LIBRARIES}")
      set(OTHER_PYTHON_VERSION_STRING "${Python2_VERSION}")
      set(OTHER_PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}")
      set(OTHER_PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}")
      set(OTHER_PYTHON_UNDER_VERSION_STRING "${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}")
      set(OTHER_NUMPY_FOUND ${Python2_NumPy_FOUND})
      set(OTHER_NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}")
    endif()
  endif()

  if(NOT Python3_Development_FOUND AND (NOT Python2_Development_FOUND OR "${Python2_VERSION}" VERSION_LESS "2.7"))
    message(WARNING "No supported Python 2 or 3 development packages were found; PyROOT will not be built.")
  endif()

  # Print message saying with which versions of Python are used to build
  if(pyroot_experimental)
    if(NOT Python3_Development_FOUND OR NOT Python2_Development_FOUND)
      message(STATUS "Main Python used to build: ${PYTHON_VERSION_MAJOR}; PyROOT built for version ${PYTHON_VERSION_MAJOR} ")
    elseif(Python3_Development_FOUND AND Python2_Development_FOUND)
      message(STATUS "Main Python used to build: ${PYTHON_VERSION_MAJOR}; PyROOT built for versions ${PYTHON_VERSION_MAJOR} and ${OTHER_PYTHON_VERSION_MAJOR}")
    endif()
  endif()
<commit_msg>[CMake][Exp PyROOT] Build only one PyROOT version if either PYTHON_EXECUTABLE or Python_EXECUTABLE are passed<commit_after># Copyright (C) 1995-2019, <NAME> and <NAME>.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

#---Check for Python installation-------------------------------------------------------

message(STATUS "Looking for Python")

if(pyroot_experimental)
  unset(PYTHON_INCLUDE_DIR CACHE)
  unset(PYTHON_LIBRARY CACHE)
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)

  if(PYTHON_EXECUTABLE OR Python_EXECUTABLE)
    # - Check if the PYTHON_EXECUTABLE deprecated variable or Python_EXECUTABLE
    # was passed by the user; if so, PyROOT will be built with a single version
    if(PYTHON_EXECUTABLE)
      set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
    endif()
    execute_process(COMMAND ${Python_EXECUTABLE} -c "import sys;print(sys.version_info[0])"
                    OUTPUT_VARIABLE PYTHON_PREFER_VERSION
                    ERROR_VARIABLE PYTHON_PREFER_VERSION_ERR)
    if(PYTHON_PREFER_VERSION_ERR)
      message(WARNING "Unable to determine version of ${Python_EXECUTABLE}: ${PYTHON_PREFER_VERSION_ERR}")
    endif()
    string(STRIP "${PYTHON_PREFER_VERSION}" PYTHON_PREFER_VERSION)
    find_package(Python COMPONENTS Interpreter Development NumPy)
    if(Python_Development_FOUND)
      set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}" CACHE INTERNAL "" FORCE)
      set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
      set(PYTHON_LIBRARIES "${Python_LIBRARIES}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_STRING "${Python_VERSION}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_UNDER_VERSION_STRING "${Python_VERSION_MAJOR}_${Python_VERSION_MINOR}")
      set(NUMPY_FOUND ${Python_NumPy_FOUND} CACHE INTERNAL "" FORCE)
      set(NUMPY_INCLUDE_DIRS "${Python_NumPy_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
    endif()
    if(DEFINED Python_VERSION AND "${Python_VERSION}" VERSION_LESS "2.7")
      message(WARNING "Ignoring Python installation: unsupported version ${Python_VERSION} (version>=2.7 required)")
    endif()
    if(Python_Development_FOUND)
      message(STATUS "PyROOT will be built for version ${PYTHON_VERSION_MAJOR}")
    else()
      message(WARNING "No supported Python development package was found for the specified Python executable; PyROOT will not be built")
    endif()

  else()
    # - Look for Python3 and set the deprecated variables to the ones set
    # automatically by find_package(Python3 ...)
    # - Look for Python2 and set the deprecated variables to the ones set
    # automatically by find_package(Python2 ...) ONLY IF PYTHON3 WASN'T FOUND
    find_package(Python3 COMPONENTS Interpreter Development NumPy)
    if(Python3_Development_FOUND)
      set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}" CACHE INTERNAL "" FORCE)
      set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
      set(PYTHON_LIBRARIES "${Python3_LIBRARIES}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_STRING "${Python3_VERSION}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MAJOR "${Python3_VERSION_MAJOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_VERSION_MINOR "${Python3_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
      set(PYTHON_UNDER_VERSION_STRING "${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}")
      set(NUMPY_FOUND ${Python3_NumPy_FOUND} CACHE INTERNAL "" FORCE)
      set(NUMPY_INCLUDE_DIRS "${Python3_NumPy_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
    endif()

    find_package(Python2 COMPONENTS Interpreter Development NumPy)
    if(DEFINED Python2_VERSION AND "${Python2_VERSION}" VERSION_LESS "2.7")
      message(WARNING "Ignoring Python2 installation: unsupported version ${Python2_VERSION} (version>=2.7 required)")
    endif()
    if(Python2_Development_FOUND AND "${Python2_VERSION}" VERSION_GREATER_EQUAL "2.7")
      if(NOT Python3_Development_FOUND)
        # Only Python2 was found, set as main
        set(PYTHON_EXECUTABLE "${Python2_EXECUTABLE}" CACHE INTERNAL "" FORCE)
        set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
        set(PYTHON_LIBRARIES "${Python2_LIBRARIES}" CACHE INTERNAL "" FORCE)
        set(PYTHON_VERSION_STRING "${Python2_VERSION}" CACHE INTERNAL "" FORCE)
        set(PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}" CACHE INTERNAL "" FORCE)
        set(PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
        set(PYTHON_UNDER_VERSION_STRING "${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}")
        set(NUMPY_FOUND ${Python2_NumPy_FOUND} CACHE INTERNAL "" FORCE)
        set(NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
      else()
        # Both Python3 and 2 found, set 2 as 'other'
        set(OTHER_PYTHON_EXECUTABLE "${Python2_EXECUTABLE}")
        set(OTHER_PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}")
        set(OTHER_PYTHON_LIBRARIES "${Python2_LIBRARIES}")
        set(OTHER_PYTHON_VERSION_STRING "${Python2_VERSION}")
        set(OTHER_PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}")
        set(OTHER_PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}")
        set(OTHER_PYTHON_UNDER_VERSION_STRING "${Python2_VERSION_MAJOR}_${Python2_VERSION_MINOR}")
        set(OTHER_NUMPY_FOUND ${Python2_NumPy_FOUND})
        set(OTHER_NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}")
      endif()
    endif()

    if(NOT Python3_Development_FOUND AND (NOT Python2_Development_FOUND OR "${Python2_VERSION}" VERSION_LESS "2.7"))
      message(WARNING "No supported Python 2 or 3 development packages were found; PyROOT will not be built.")
    endif()

    # Print message saying with which versions of Python are used to build
    if(pyroot_experimental)
      if(NOT Python3_Development_FOUND OR NOT Python2_Development_FOUND)
        message(STATUS "Main Python used to build: ${PYTHON_VERSION_MAJOR}; PyROOT built for version ${PYTHON_VERSION_MAJOR} ")
      elseif(Python3_Development_FOUND AND Python2_Development_FOUND)
        message(STATUS "Main Python used to build: ${PYTHON_VERSION_MAJOR}; PyROOT built for versions ${PYTHON_VERSION_MAJOR} and ${OTHER_PYTHON_VERSION_MAJOR}")
      endif()
    endif()
  endif()

{'fraction_non_alphanumeric': 0.10234899328859061, 'fraction_numerical': 0.014305898975626986, 'mean_word_length': 4.8076923076923075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3732183', 'n_tokens_mistral': 4085, 'n_tokens_neox': 3727, 'n_words': 827}