From 40b1247b84cac6e6560c8a489e43b000086e2265 Mon Sep 17 00:00:00 2001 From: tgoff0 Date: Thu, 19 Feb 2015 18:12:44 +0000 Subject: [PATCH] Improve python install prefix determination. --- configure.ac | 2 +- python-prefix.py | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 96f85480..dc26b29e 100644 --- a/configure.ac +++ b/configure.ac @@ -236,7 +236,7 @@ if test "x$want_python" = "xyes"; then AC_SUBST(libev_CFLAGS) AC_SUBST(libev_LIBS, [-lev]), AC_MSG_ERROR([Python bindings require libev (try installing your 'libev-devel' or 'libev-dev' package)]))) - AC_SUBST(pyprefix, `eval ./python-prefix.py ${PYTHON_PREFIX}`) + AC_SUBST(pyprefix, `eval ${PYTHON} ./python-prefix.py ${PYTHON_PREFIX} ${PYTHON_VERSION}`) if test "${pyprefix}" != "${PYTHON_PREFIX}"; then pythondir=`echo ${pythondir} | sed -e 's,[$][{]prefix[}],${pyprefix},g'` pyexecdir=`echo ${pyexecdir} | sed -e 's,[$][{]exec_prefix[}],${pyprefix},g'` diff --git a/python-prefix.py b/python-prefix.py index 55379561..3b6ddeff 100755 --- a/python-prefix.py +++ b/python-prefix.py @@ -5,19 +5,30 @@ import os.path import site def main(): - if len(sys.argv) != 2: - msg = 'usage: %s \n' % os.path.basename(sys.argv[0]) + '''\ + Check if the given prefix is included in sys.path for the given + python version; if not find an alternate valid prefix. Print the + result to standard out. + ''' + if len(sys.argv) != 3: + msg = 'usage: %s \n' % \ + os.path.basename(sys.argv[0]) sys.stderr.write(msg) return 1 python_prefix = sys.argv[1] + python_version = sys.argv[2] + path = '%s/lib/python%s' % (python_prefix, python_version) + path = os.path.normpath(path) + if path[-1] != '/': + path = path + '/' prefix = None for p in sys.path: - if python_prefix in p: - prefix = python_prefix + if p.startswith(path): + prefix = path break if not prefix: prefix = site.PREFIXES[-1] - print prefix + sys.stdout.write('%s\n' % prefix) return 0 if __name__ == '__main__':