[libvirt] [PATCH] Use AM_PATH_PYTHON and python-config to detect Python configuration

Matthias Bolte matthias.bolte at googlemail.com
Sun Dec 6 22:02:26 UTC 2009


Using AM_PATH_PYTHON solves the site-packages directory problem. At least
in Ubuntu with Python 2.6 and later site-packages is renamed to dist-packages
and site-packages is not part of sys.path anymore. So installing the libvirt
Python bindings to site-packages renders them unusable, because they can be
imported from there without manually including site-packages into sys.path.

AM_PATH_PYTHON detects the correct site-packages/dist-packages directory.

python-config --includes gives the correct include path for the Python header
files. The old probing code stays there as fallback mechanism.

* configure.in: use AM_PATH_PYTHON and python-config
* python/Makefile.am: remove -I because PYTHON_INCLUDES contains it now
---
 configure.in       |  110 +++++++++++++++++++++++++---------------------------
 python/Makefile.am |    2 +-
 2 files changed, 54 insertions(+), 58 deletions(-)

diff --git a/configure.in b/configure.in
index f735bba..d6e5979 100644
--- a/configure.in
+++ b/configure.in
@@ -1414,75 +1414,71 @@ AC_ARG_WITH([python],
 
 PYTHON_VERSION=
 PYTHON_INCLUDES=
-PYTHON_SITE_PACKAGES=
-PYTHON_TESTS=
 pythondir=
 if test "$with_python" != "no" ; then
     if test -x "$with_python/bin/python"
     then
-        echo Found python in $with_python/bin/python
+        AC_MSG_NOTICE(Found python in $with_python/bin/python)
         PYTHON="$with_python/bin/python"
+        with_python=yes
     else
-	if test -x "$with_python"
-	then
-	    echo Found python in $with_python
-	    PYTHON="$with_python"
-	else
-	    if test -x "$PYTHON"
-	    then
-	        echo Found python in environment PYTHON=$PYTHON
-		with_python=`$PYTHON -c "import sys; print sys.exec_prefix"`
-	    else
-		AC_PATH_PROG([PYTHON], [python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5])
-	    fi
-	fi
-    fi
-    if test "$PYTHON" != ""
-    then
-        PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
-	echo Found Python version $PYTHON_VERSION
-    fi
-    if test "$PYTHON_VERSION" != ""
-    then
-	if test -r $with_python/include/python$PYTHON_VERSION/Python.h -a \
-	   -d $with_python/lib/python$PYTHON_VERSION/site-packages
-	then
-	    PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION
-	    PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
-	else
-	    if test -r $prefix/include/python$PYTHON_VERSION/Python.h
-	    then
-	        PYTHON_INCLUDES=$prefix/include/python$PYTHON_VERSION
-	        PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
-	    else
-		if test -r /usr/include/python$PYTHON_VERSION/Python.h
-		then
-		    PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
-	            PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
-		else
-		    echo could not find python$PYTHON_VERSION/Python.h
-		fi
-	    fi
-	    if test ! -d "$PYTHON_SITE_PACKAGES"
-	    then
-		    PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"`
-	    fi
-	fi
+        if test -x "$with_python"
+        then
+            AC_MSG_NOTICE(Found python in $with_python)
+            PYTHON="$with_python"
+            with_python=yes
+        else
+            if test -x "$PYTHON"
+            then
+                AC_MSG_NOTICE(Found python in environment PYTHON=$PYTHON)
+                with_python=yes
+            fi
+        fi
     fi
-    if test "$with_python" != "yes"
-    then
-        pythondir='$(PYTHON_SITE_PACKAGES)'
+
+    if test "$with_python" == "yes" ; then
+        AM_PATH_PYTHON(,, [:])
+
+        if test "$PYTHON" != : ; then
+            PYTHON_CONFIG="$PYTHON-config"
+
+            if test -x "$PYTHON_CONFIG"
+            then
+                PYTHON_INCLUDES=`$PYTHON_CONFIG --includes`
+            else
+                if test -r $PYTHON_EXEC_PREFIX/include/python$PYTHON_VERSION/Python.h
+                then
+                    PYTHON_INCLUDES=-I$PYTHON_EXEC_PREFIX/include/python$PYTHON_VERSION
+                else
+                    if test -r $prefix/include/python$PYTHON_VERSION/Python.h
+                    then
+                        PYTHON_INCLUDES=-I$prefix/include/python$PYTHON_VERSION
+                    else
+                        if test -r /usr/include/python$PYTHON_VERSION/Python.h
+                        then
+                            PYTHON_INCLUDES=-I/usr/include/python$PYTHON_VERSION
+                        else
+                            AC_MSG_NOTICE([Could not find python$PYTHON_VERSION/Python.h, disabling bindings])
+                            with_python=no
+                        fi
+                    fi
+                fi
+            fi
+        else
+            AC_MSG_NOTICE([Could not find python interpreter, disabling bindings])
+            with_python=no
+        fi
     else
-        pythondir='$(libdir)/python$(PYTHON_VERSION)/site-packages'
+        AC_MSG_NOTICE([Could not find python in $with_python, disabling bindings])
+        with_python=no
     fi
-else
-    PYTHON=
 fi
-AM_CONDITIONAL([WITH_PYTHON], test "$PYTHON_INCLUDES" != "")
-AC_SUBST([pythondir])
+AM_CONDITIONAL([WITH_PYTHON], [test "$with_python" = "yes"])
 AC_SUBST([PYTHON_VERSION])
 AC_SUBST([PYTHON_INCLUDES])
-AC_SUBST([PYTHON_SITE_PACKAGES])
+AC_SUBST([pythondir])
+
+
 
 AC_MSG_CHECKING([whether this host is running a Xen kernel])
 RUNNING_XEN=
diff --git a/python/Makefile.am b/python/Makefile.am
index cda6559..736631e 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -4,7 +4,7 @@ SUBDIRS= . tests
 
 INCLUDES = \
         $(WARN_CFLAGS) \
-        -I$(PYTHON_INCLUDES) \
+        $(PYTHON_INCLUDES) \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include \
 	-I$(top_builddir)/$(subdir)
-- 
1.6.0.4




More information about the libvir-list mailing list