Detect Python packages directory on configure
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Oct 2014 20:36:10 +0000 (16:36 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Oct 2014 20:36:10 +0000 (16:36 -0400)
The Python interpreter on Debian is configurated to use
...lib/python.../dist-packages instead of
.../lib/python.../site-packages to look for extra modules.

python_modules.m4 performs a runtime python check of the
sys.path variable to check wether the selected interpreter is
configurated to use site-packages vs dist-packages.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
m4/python_modules.m4 [new file with mode: 0644]

index bccbcde24269aa0f58e39d342462bb377d797b52..eb14fbd5c337ff343bb7de8fc9905b1f162a9713 100644 (file)
@@ -123,6 +123,11 @@ if test "x${enable_python:-yes}" = xyes; then
   AX_PKG_SWIG($swig_version, [], [ AC_MSG_ERROR([SWIG $swig_version or newer is needed]) ])
   AM_PATH_PYTHON([3.0], , [AC_MSG_ERROR(Python3 is not available or is not the default Python interpreter on your system. See the README file to learn how to override your distribution's default Python interpreter.)])
 
+  AM_PATH_PYTHON_MODULES([PYTHON])
+  # pythondir is the path where extra modules are to be installed
+  pythondir=$PYTHON_PREFIX/$PYTHON_MODULES_PATH
+  # pyexecdir is the path that contains shared objects used by the extra modules
+  pyexecdir=$PYTHON_EXEC_PREFIX/$PYTHON_MODULES_PATH
   AC_ARG_VAR([PYTHON_INCLUDE], [Include flags for python, bypassing python-config])
   AC_ARG_VAR([PYTHON_CONFIG], [Path to python-config])
   AS_IF([test -z "$PYTHON_INCLUDE"], [
diff --git a/m4/python_modules.m4 b/m4/python_modules.m4
new file mode 100644 (file)
index 0000000..132c4c2
--- /dev/null
@@ -0,0 +1,23 @@
+# python_modules.m4 -- Get the Python modules install path
+#
+# Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# While extra Python modules are generaly installed in the Python
+# interpreter's "site-packages" directory, Debian prefers using the
+# "dist-packages" nomenclature. This macro uses the interpreter
+# designated by the PYTHON variable to check the interpreter's PATH
+# and sets the PYTHON_MODULES_PATH by taking the prefix into account.
+
+# AM_PATH_PYTHON_MODULES(PYTHON)
+# ---------------------------------------------------------------------------
+AC_DEFUN([AM_PATH_PYTHON_MODULES],
+ [prog="import sys
+for path in sys.path:
+    if path.endswith(\"-packages\"):
+       print(path[[path.find(\"/lib\"):]])
+       break"
+  PYTHON_MODULES_PATH=`${$1} -c "$prog"`])
This page took 0.026548 seconds and 4 git commands to generate.