diff options
Diffstat (limited to 'host')
| -rw-r--r-- | host/CMakeLists.txt | 41 | ||||
| -rw-r--r-- | host/cmake/Modules/UHDPython.cmake | 112 | ||||
| -rw-r--r-- | host/python/CMakeLists.txt | 3 | 
3 files changed, 124 insertions, 32 deletions
| diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 0a3bf3d83..3a523ad5d 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -34,6 +34,7 @@ set(MSVC_MIN_VERSION_READABLE "15.0")  # all the build-time Python scripts  set(PYTHON_MIN_VERSION "3.6")  # Other deps +set(SETUPTOOLS_MIN_VERSION "40.0")  set(BOOST_MIN_VERSION "1.65")  set(NUMPY_MIN_VERSION "1.11")  set(RUAMEL.YAML_MIN_VERSION "0.15") @@ -310,33 +311,43 @@ include(UHDLog)  ########################################################################  include(UHDPython) -PYTHON_CHECK_MODULE( -    "Python version ${PYTHON_MIN_VERSION} or greater" -    "platform" "LooseVersion(platform.python_version()) >= LooseVersion('${PYTHON_MIN_VERSION}')" +PYTHON_CHECK_MODULE_VERSION( +    "compatible Python version" +    "platform" +    "platform.python_version()" +    ${PYTHON_MIN_VERSION}      HAVE_PYTHON_PLAT_MIN_VERSION  ) -PYTHON_CHECK_MODULE( -    "Mako templates ${PY_MAKO_MIN_VERSION} or greater" -    "mako" "LooseVersion(mako.__version__) >= LooseVersion('${PY_MAKO_MIN_VERSION}')" +PYTHON_CHECK_MODULE_VERSION( +    "Mako templates module" +    "mako" +    "mako.__version__" +    ${PY_MAKO_MIN_VERSION}      HAVE_PYTHON_MODULE_MAKO  ) -PYTHON_CHECK_MODULE( -    "requests ${PY_REQUESTS_MIN_VERSION} or greater" -    "requests" "LooseVersion(requests.__version__) >= LooseVersion('${PY_REQUESTS_MIN_VERSION}')" +PYTHON_CHECK_MODULE_VERSION( +    "requests module" +    "requests" +    "requests.__version__" +    ${PY_REQUESTS_MIN_VERSION}      HAVE_PYTHON_MODULE_REQUESTS  ) -PYTHON_CHECK_MODULE( -    "numpy ${NUMPY_MIN_VERSION} or greater" -    "numpy" "LooseVersion(numpy.__version__) >= LooseVersion('${NUMPY_MIN_VERSION}')" +PYTHON_CHECK_MODULE_VERSION( +    "numpy module" +    "numpy" +    "numpy.__version__" +    ${NUMPY_MIN_VERSION}      HAVE_PYTHON_MODULE_NUMPY  ) -PYTHON_CHECK_MODULE( -    "ruamel.yaml ${RUAMEL.YAML_MIN_VERSION} or greater" -    "ruamel.yaml" "LooseVersion(ruamel.yaml.__version__) >= LooseVersion('${RUAMEL.YAML_MIN_VERSION}')" +PYTHON_CHECK_MODULE_VERSION( +    "ruamel.yaml module" +    "ruamel.yaml" +    "ruamel.yaml.__version__" +    ${RUAMEL.YAML_MIN_VERSION}      HAVE_PYTHON_MODULE_YAML  ) diff --git a/host/cmake/Modules/UHDPython.cmake b/host/cmake/Modules/UHDPython.cmake index 935a6a819..b68e18453 100644 --- a/host/cmake/Modules/UHDPython.cmake +++ b/host/cmake/Modules/UHDPython.cmake @@ -119,36 +119,116 @@ set(RUNTIME_PYTHON_EXECUTABLE ${RUNTIME_PYTHON_EXECUTABLE} CACHE FILEPATH  message(STATUS "Python runtime interpreter: ${RUNTIME_PYTHON_EXECUTABLE} Version: ${RUNTIME_PYTHON_VERSION}")  message(STATUS "Override with: -DRUNTIME_PYTHON_EXECUTABLE=<path-to-python>") -macro(PYTHON_CHECK_MODULE desc mod cmd have) +############################################################################### +# Determine if a Python module is installed, or, more generally, determine +# if some condition that Python can report through a Boolean expression is +# met. This macro allows one or more modules to be imported and a Python +# Boolean expression to be evaluated. +# +# - desc: +#    Description of what's being checked (for user feedback) +# - module: +#    The module(s) to be passed to the `import` command +# - bool_expr: +#    A Python expression to be evaluated that returns True or False based on +#    the presence or absence of the module (or in the general case, the +#    condition being checked) +# - have_ver: +#    The variable name to be set to TRUE if the Python expression returns True, +#    or FALSE otherwise +macro(PYTHON_CHECK_MODULE desc module bool_expr have_var)      message(STATUS "")      message(STATUS "Python checking for ${desc}")      execute_process(          COMMAND ${PYTHON_EXECUTABLE} -c "  ######################################### -from distutils.version import LooseVersion -try: import ${mod} -except: exit(1) -try: assert ${cmd} -except: exit(2) +try: +    import ${module} +except: +    exit(1) +try: +    assert ${bool_expr} +except: +    exit(2)  exit(0)  #########################################" -        RESULT_VARIABLE ${have} +        RESULT_VARIABLE python_result      ) -    if(${have} EQUAL 0) +    if(python_result EQUAL 0)          message(STATUS "Python checking for ${desc} - found") -        set(${have} TRUE) -    elseif(${have} EQUAL 1) -        message(STATUS "Python checking for ${desc} - \"import ${mod}\" failed") -        set(${have} FALSE) -    elseif(${have} EQUAL 2) -        message(STATUS "Python checking for ${desc} - \"assert ${cmd}\" failed") -        set(${have} FALSE) +        set(${have_var} TRUE) +    elseif(python_result EQUAL 1) +        message(STATUS "Python checking for ${desc} - \"import ${module}\" failed (is it installed?)") +        set(${have_var} FALSE) +    elseif(python_result EQUAL 2) +        message(STATUS "Python checking for ${desc} - \"assert ${bool_expr}\" failed") +        set(${have_var} FALSE)      else()          message(STATUS "Python checking for ${desc} - unknown error") -        set(${have} FALSE) +        set(${have_var} FALSE)      endif()  endmacro(PYTHON_CHECK_MODULE) + +############################################################################### +# Determine if a Python module is installed and if it meets a minimum required +# version. +# +# - desc: +#    Description of what's being checked (for user feedback) +# - module: +#    The module to be `import`ed +# - module_version_expr: +#    A Python expression to be evaluated that returns the module version string +#    (usually "module_name.__version__", but may be tailored for non-conformant +#    modules, or other custom use cases) +# - min_module_version: +#    The minimum version required of the module as a canonical Python version +#    string ("major.minor.micro") as defined in PEP 440 +# - have_ver: +#    The variable name to be set to TRUE if the module is present and meets +#    the minimum version requirement or FALSE otherwise +macro(PYTHON_CHECK_MODULE_VERSION desc module module_version_expr min_module_version have_var) +    message(STATUS "") +    message(STATUS "Python checking for ${desc}") +    execute_process( +        COMMAND ${PYTHON_EXECUTABLE} -c " +######################################### +try: +    import ${module} +except: +    exit(1) +try: +    version = ${module_version_expr} +    print(version) +except: +    exit(2) +exit(0) +#########################################" +        RESULT_VARIABLE python_result +        OUTPUT_VARIABLE version_output +        OUTPUT_STRIP_TRAILING_WHITESPACE +    ) +    if(python_result EQUAL 0) +        if(${version_output} VERSION_GREATER_EQUAL ${min_module_version}) +            message(STATUS "Python checking for ${desc} - ${version_output} satisifes minimum required version ${min_module_version}") +            set(${have_var} TRUE) +        else() +            message(STATUS "Python checking for ${desc} - ${version_output} does not satisfy minimum required version ${min_module_version}") +            set(${have_var} FALSE) +        endif() +    elseif(python_result EQUAL 1) +        message(STATUS "Python checking for ${desc} - \"import ${module}\" failed (is it installed?)") +        set(${have_var} FALSE) +    elseif(python_result EQUAL 2) +        message(STATUS "Python checking for ${desc} - evaluation of \"${module_version_expr}\" failed") +        set(${have_var} FALSE) +    else() +        message(STATUS "Python checking for ${desc} - unknown error") +        set(${have_var} FALSE) +    endif() +endmacro(PYTHON_CHECK_MODULE_VERSION) +  ###############################################################################  # Part 2: Python Libraries  ############################################################################### diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt index 212bd9e46..a7f0352af 100644 --- a/host/python/CMakeLists.txt +++ b/host/python/CMakeLists.txt @@ -10,7 +10,8 @@  PYTHON_CHECK_MODULE(      "virtualenv" -    "sys" "hasattr(sys, 'real_prefix')" +    "sys" +    "hasattr(sys, 'real_prefix')"      HAVE_PYTHON_VIRTUALENV  ) | 
