[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-buildsystem
Subject:    [PATCH]: Better FindPython Stuff (bug 174806)
From:       Allen Winter <winter () kde ! org>
Date:       2009-03-15 13:25:23
Message-ID: 200903150925.25186.winter () kde ! org
[Download RAW message or body]

Howdy,

I'd like to get a review of the attached patch to improve Python discovery.

This is Michael Witten's patch posted to https://bugs.kde.org/show_bug.cgi?id=174806.
I'm just the messenger.

Also, this patch provides a new $PYTHON_SITE_PACKAGES_INSTALL_DIR
where python packages can be installed (i.e. in a non-root-owned location, if desired).


-- 
Allen Winter | Software Engineer | 1-888-872-9339
KDAB, Inc. | "Platform-independent software solutions"
http://kdab.com | 1-866-777-5322 (US) | +46-563-540090 (Sweden)

["pythonstuff.patch" (text/x-patch)]

Index: cmake/modules/SIPMacros.cmake
===================================================================
--- cmake/modules/SIPMacros.cmake	(revision 939041)
+++ cmake/modules/SIPMacros.cmake	(working copy)
@@ -108,6 +108,6 @@
     TARGET_LINK_LIBRARIES(${_logical_name} ${EXTRA_LINK_LIBRARIES})
     SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME \
${_child_module_name})  
-    INSTALL(TARGETS ${_logical_name} DESTINATION \
"${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}") +    INSTALL(TARGETS \
${_logical_name} DESTINATION \
"${PYTHON_SITE_PACKAGES_INSTALL_DIR}/${_parent_module_path}")  
 ENDMACRO(ADD_SIP_PYTHON_MODULE)
Index: cmake/modules/FindLibPython.py
===================================================================
--- cmake/modules/FindLibPython.py	(revision 939041)
+++ cmake/modules/FindLibPython.py	(working copy)
@@ -1,13 +1,33 @@
-
 # Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
+# Copyright (c) 2009, Michael Witten <mfwitten@gmail.com>
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
-import sys
-import distutils.sysconfig
+import sys, site, distutils.sysconfig
 
-print("exec_prefix:%s" % sys.exec_prefix)
-print("short_version:%s" % sys.version[:3])
-print("long_version:%s" % sys.version.split()[0])
-print("py_inc_dir:%s" % distutils.sysconfig.get_python_inc())
-print("site_packages_dir:%s" % distutils.sysconfig.get_python_lib(plat_specific=1))
+if len(sys.argv) <= 1:
+
+    print("exec_prefix:%s" % sys.exec_prefix)
+    print("short_version:%d.%d" % tuple(sys.version_info[:2]))
+    print("long_version:%d.%d.%d" % tuple(sys.version_info[:3]))
+    print("py_inc_dir:%s" % distutils.sysconfig.get_python_inc())
+    print("site_packages_dir:%s" % \
distutils.sysconfig.get_python_lib(plat_specific=1)) +    \
print("user_site_packages_dir:%s" % getattr(site, 'USER_SITE', 'NOTFOUND')) +
+else:
+
+    a = sys.argv[1]
+    p = sys.stdout.write
+
+    if a == 'exec_prefix':
+        p(sys.exec_prefix)
+    elif a == 'short_version':
+        p("%d.%d" % tuple(sys.version_info[:2]))
+    elif a == 'long_version':
+        p("%d.%d.%d" % tuple(sys.version_info[:3]))
+    elif a == 'py_inc_dir':
+        p(distutils.sysconfig.get_python_inc())
+    elif a == 'site_packages_dir':
+        p(distutils.sysconfig.get_python_lib(plat_specific=1))
+    elif a == 'user_site_packages_dir':
+        p(getattr(site, 'USER_SITE', 'NOTFOUND'))
Index: cmake/modules/FindPythonLibrary.cmake
===================================================================
--- cmake/modules/FindPythonLibrary.cmake	(revision 939041)
+++ cmake/modules/FindPythonLibrary.cmake	(working copy)
@@ -14,11 +14,17 @@
 #
 # PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
 #
+# PYTHON_USER_SITE_PACKAGES_DIR - Location of the current user's site-packages \
directory; +#     This is useful for developers, who want to install everything under \
${HOME}. +#
+# PYTHON_SITE_PACKAGES_INSTALL_DIR - Multiplexer between \
PYTHON_{,USER_}SITE_PACKAGES_DIR +#
 # PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
 #
 # PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
 
 # Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
+# Copyright (c) 2009, Michael Witten <mfwitten@gmail.com>
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
@@ -37,21 +43,58 @@
 
     FIND_FILE(_find_lib_python_py FindLibPython.py PATHS ${CMAKE_MODULE_PATH})
 
-    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE}  ${_find_lib_python_py} \
                OUTPUT_VARIABLE python_config)
-    if(python_config)
-      STRING(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX \
                ${python_config})
-      STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" \
                PYTHON_SHORT_VERSION ${python_config})
-      STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" PYTHON_LONG_VERSION \
                ${python_config})
-      STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_PATH \
                ${python_config})
-      STRING(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" \
                PYTHON_SITE_PACKAGES_DIR ${python_config})
-      STRING(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_SHORT_VERSION_NO_DOT \
                ${PYTHON_SHORT_VERSION})
-      set(PYTHON_LIBRARY_NAMES python${PYTHON_SHORT_VERSION} \
                python${PYTHON_SHORT_VERSION_NO_DOT})
-      if(WIN32)
-          STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR \
                ${PYTHON_SITE_PACKAGES_DIR})
-      endif(WIN32)
-      FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES} PATHS \
${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs NO_DEFAULT_PATH) +    # What seemed like \
error checking was worthless, so it has been removed; +    # In fact, error checking \
is so nontrivial in these cases, that it has +    # mostly not been attempted.
+
+    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} exec_prefix  \
OUTPUT_VARIABLE PYTHON_PREFIX) +    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} \
${_find_lib_python_py} short_version          OUTPUT_VARIABLE PYTHON_SHORT_VERSION) + \
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} long_version      \
OUTPUT_VARIABLE PYTHON_LONG_VERSION) +    EXECUTE_PROCESS(COMMAND \
${PYTHON_EXECUTABLE} ${_find_lib_python_py} py_inc_dir             OUTPUT_VARIABLE \
PYTHON_INCLUDE_PATH) +    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} \
${_find_lib_python_py} site_packages_dir      OUTPUT_VARIABLE \
PYTHON_SITE_PACKAGES_DIR) +    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} \
${_find_lib_python_py} user_site_packages_dir OUTPUT_VARIABLE \
PYTHON_USER_SITE_PACKAGES_DIR) +
+    if(WIN32)
+        STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR \
${PYTHON_SITE_PACKAGES_DIR}) +        STRING(REPLACE "\\" "/" \
PYTHON_USER_SITE_PACKAGES_DIR ${PYTHON_USER_SITE_PACKAGES_DIR}) +    endif(WIN32)
+
+    if(PYTHON_SITE_PACKAGES_INSTALL_DIR) # This variable may be supplied by the \
user. +      message(
+"User supplied -DPYTHON_SITE_PACKAGES_INSTALL_DIR=\"${PYTHON_SITE_PACKAGES_INSTALL_DIR}\"
 +I hope you know what you're doing.")
+    elseif(NOT CMAKE_INSTALL_PREFIX MATCHES "^$ENV{HOME}")
+      set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${PYTHON_SITE_PACKAGES_DIR})      # \
Presumably everything will be installed with root priveleges +    elseif \
(PYTHON_USER_SITE_PACKAGES_DIR) +      set(PYTHON_SITE_PACKAGES_INSTALL_DIR \
${PYTHON_USER_SITE_PACKAGES_DIR}) # Presumably everything will be installed without \
root priveleges +    else(PYTHON_SITE_PACKAGES_INSTALL_DIR)
+      message(SEND_ERROR
+"You have selected a CMAKE_INSTALL_PREFIX that is under \${HOME}. Usually
+this means you are a KDE developer, who intends to install everything
+without the need for greater permissions (as given by, `sudo make install'
+and its ilk). However, your version of python (${PYTHON_SHORT_VERSION})
+doesn't seem to provide a *user* site-packages directory into which the
+KDE python modules can be installed without special priveleges; this is
+usually something like ~/.local/lib/python2.6/site-packages as per PEP 370,
+which is understod by python>=2.6 (read http://docs.python.org/library/site.html).
+Currently, the only viable site-packages directory is (${PYTHON_SITE_PACKAGES_DIR}),
+which may require special access priveleges. If you think this is a gross
+misunderstanding, simply run cmake again with:
+
+    -DPYTHON_SITE_PACKAGES_INSTALL_DIR=$some_path
+
+Make sure that you have write access to $some_path (so that `make install'
+won't fail) and make sure $some_path ends up in sys.path when python
+runs")
+    endif(PYTHON_SITE_PACKAGES_INSTALL_DIR)
+
+    STRING(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_SHORT_VERSION_NO_DOT \
${PYTHON_SHORT_VERSION}) +    set(PYTHON_LIBRARY_NAMES python${PYTHON_SHORT_VERSION} \
python${PYTHON_SHORT_VERSION_NO_DOT}) +    FIND_LIBRARY(PYTHON_LIBRARY NAMES \
${PYTHON_LIBRARY_NAMES} PATHS ${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs \
NO_DEFAULT_PATH) +
+    if(PYTHON_LIBRARY)
       set(PYTHONLIBRARY_FOUND TRUE)
-    endif(python_config)
+    endif(PYTHON_LIBRARY)
 
     # adapted from cmake's builtin FindPythonLibs
     if(APPLE)
@@ -62,7 +105,6 @@
         # make sure "-framework" is used to link it.
         if("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
           set(PYTHON_LIBRARY "")
-          set(PYTHON_DEBUG_LIBRARY "")
         endif("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
         if(NOT PYTHON_LIBRARY)
           set (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" \
FORCE) @@ -78,6 +120,7 @@
       message(STATUS "Found Python executable: ${PYTHON_EXECUTABLE}")
       message(STATUS "Found Python version: ${PYTHON_LONG_VERSION}")
       message(STATUS "Found Python library: ${PYTHON_LIBRARY}")
+      message(STATUS "Using Python site-packages: \
${PYTHON_SITE_PACKAGES_INSTALL_DIR}")  endif(NOT PYTHONLIBRARY_FIND_QUIETLY)
   else(PYTHONLIBRARY_FOUND)
     if(PYTHONLIBRARY_FIND_REQUIRED)



_______________________________________________
Kde-buildsystem mailing list
Kde-buildsystem@kde.org
https://mail.kde.org/mailman/listinfo/kde-buildsystem


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic