Make requests python package to be detected in the same way as numpy
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Jul 2014 14:42:30 +0000 (20:42 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Jul 2014 14:53:02 +0000 (20:53 +0600)
This solves missing requests package reported on the systems where it's
located in dist-packages rather than in site-packages.

To do this there's now a helper macros which handles both requests and
numpy now and could be used for more packages in the future.

Reviewers: campbellbarton

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D686

CMakeLists.txt
build_files/cmake/macros.cmake
source/creator/CMakeLists.txt

index 9de92af9a820d2708c15b38d510f262d14772675..9f32f79049bedf1ff6879436ed30fd97a99234a0 100644 (file)
@@ -257,11 +257,13 @@ if(UNIX AND NOT APPLE)
 endif()
 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
-set(PYTHON_NUMPY_PATH            "" CACHE PATH "Python to python site-packages or dist-packages containing 'numpy' module")
+set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
 mark_as_advanced(PYTHON_NUMPY_PATH)
 
 if(UNIX AND NOT APPLE)
        option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
+       set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
+       mark_as_advanced(PYTHON_REQUESTS_PATH)
 endif()
 
 # Cycles
@@ -2245,62 +2247,13 @@ if(WITH_PYTHON)
        if(WIN32)
                # pass, we have this in an archive to extract
        elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
-               # set but invalid
-               # -- disabled until we make numpy bundled with blender - campbell
-               if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
-#                      if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
-#                              message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
-#                                              "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
-#                              set(WITH_PYTHON_INSTALL_NUMPY OFF)
-#                      endif()
-               # not set, so initialize
-               else()
-                       string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
-                       list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
-
-                       # re-cache
-                       unset(PYTHON_NUMPY_PATH CACHE)
-                       find_path(PYTHON_NUMPY_PATH
-                         NAMES
-                           numpy
-                         HINTS
-                           "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
-                           "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
-                         PATH_SUFFIXES
-                           site-packages
-                           dist-packages
-                          NO_DEFAULT_PATH
-                       )
-
-                       if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
-                               message(WARNING "'numpy' path could not be found in:\n"
-                                               "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
-                                               "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
-                                               "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
-                                               "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
-                                               "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
-                               set(WITH_PYTHON_INSTALL_NUMPY OFF)
-                       else()
-                               message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
-                       endif()
-
-                       unset(_PY_VER_SPLIT)
-                       unset(_PY_VER_MAJOR)
-               endif()
+               find_python_package(numpy)
        endif()
 
        if(WIN32 OR APPLE)
                # pass, we have this in lib/python/site-packages
        elseif(WITH_PYTHON_INSTALL_REQUESTS)
-               if(NOT EXISTS ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests)
-                       # gets annoying otherwise...
-                       if(FIRST_RUN)
-                               message(WARNING "'requests' path could not be found in:\n"
-                                               "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests'\n"
-                                               "WITH_PYTHON_INSTALL_REQUESTS option will be ignored when installing python")
-                       endif()
-                       set(WITH_PYTHON_INSTALL_REQUESTS OFF)
-               endif()
+               find_python_package(requests)
        endif()
 endif()
 
index 8890c137dd2dc2af408c814461edffb8a41076ce..f896fb9d6a91b578ee8156bb931e2789270f935a 100644 (file)
@@ -1324,3 +1324,54 @@ macro(msgfmt_simple
        unset(_file_to)
        unset(_file_to_path)
 endmacro()
+
+macro(find_python_package
+      package)
+
+       string(TOUPPER ${package} _upper_package)
+
+       # set but invalid
+       if((NOT ${PYTHON_${_upper_package}_PATH} STREQUAL "") AND
+          (NOT ${PYTHON_${_upper_package}_PATH} MATCHES NOTFOUND))
+#              if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}/${package}")
+#                      message(WARNING "PYTHON_${_upper_package}_PATH is invalid, ${package} not found in '${PYTHON_${_upper_package}_PATH}' "
+#                                      "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
+#                      set(WITH_PYTHON_INSTALL${_upper_package} OFF)
+#              endif()
+       # not set, so initialize
+       else()
+               string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
+               list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
+
+               # re-cache
+               unset(PYTHON_${_upper_package}_PATH CACHE)
+               find_path(PYTHON_${_upper_package}_PATH
+                 NAMES
+                   ${package}
+                 HINTS
+                   "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
+                   "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
+                 PATH_SUFFIXES
+                   site-packages
+                   dist-packages
+                  NO_DEFAULT_PATH
+               )
+
+                if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
+                       message(WARNING "'${package}' path could not be found in:\n"
+                                       "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${package}', "
+                                       "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${package}', "
+                                       "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
+                                       "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
+                                       "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
+                       set(WITH_PYTHON_INSTALL_${_upper_package} OFF)
+               else()
+                       message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
+               endif()
+
+               unset(_PY_VER_SPLIT)
+               unset(_PY_VER_MAJOR)
+         endif()
+
+         unset(_upper_package)
+endmacro()
index 8deadb9c7b7a2c774351f5f96b6f2bcf37ac85eb..bd223b8d5400096380143d969ddef56ef9976b78 100644 (file)
@@ -539,7 +539,7 @@ if(UNIX AND NOT APPLE)
                        # Copy requests, we need to generalize site-packages
                        if(WITH_PYTHON_INSTALL_REQUESTS)
                                install(
-                                       DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests
+                                       DIRECTORY ${PYTHON_REQUESTS_PATH}/requests
                                        DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/site-packages
                                        PATTERN ".svn" EXCLUDE
                                        PATTERN "__pycache__" EXCLUDE           # * any cache *