meson: Fix pythondetector on Debian and use sysconfig for getting the ABIFLAGS too
authorSebastian Dröge <sebastian@centricular.com>
Wed, 14 Sep 2016 09:42:54 +0000 (11:42 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 14 Sep 2016 11:42:49 +0000 (13:42 +0200)
Paths like /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu would not be
detected by the old code, but it's all nicely stored in sysconfig so
let's just use that.

pythondetector

index 37aa80f..bc3c31f 100644 (file)
@@ -8,12 +8,7 @@ from distutils import sysconfig
 
 
 def get_python_abiflags():
-    try:
-        return subprocess.check_output([os.path.basename(sys.executable) + '-config',
-                                        '--abiflags']).decode(errors='ignore').strip()
-    except FileNotFoundError:
-        return ''
-
+    return sysconfig.get_config_var("ABIFLAGS")
 
 def get_python_libloc():
     # OSX is a pain. Python as shipped by apple installs libpython in /usr/lib
@@ -22,30 +17,11 @@ def get_python_libloc():
     if platform.system().lower() == 'darwin':
         return '/usr/lib'
 
-    python_libs = sysconfig.get_python_lib(standard_lib=1)
-    pylib_loc = python_libs + '/config'
-    pyversion = "%d.%d" % (sys.version_info.major, sys.version_info.minor)
-
-    abiflags = get_python_abiflags()
-    py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
-    if os.path.exists(os.path.join(py_sharedlib)):
-        return pylib_loc
-
-    pylib_loc = sys.prefix + '/lib64'
-    py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
-
-    if os.path.exists(os.path.join(py_sharedlib)):
-        return pylib_loc
-
-    pylib_loc = sys.prefix + '/lib'
-    py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
-    if os.path.exists(os.path.join(py_sharedlib)):
-        return pylib_loc
+    pylib_loc = sysconfig.get_config_var("LIBPL")
+    pylib_ldlibrary = sysconfig.get_config_var("LDLIBRARY")
 
-    libdir = 'lib64' if os.path.isdir('/usr/lib64') else 'lib'
-    pylib_loc = '/usr/' + libdir
-    py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
-    if os.path.exists(os.path.join(py_sharedlib)):
+    py_sharedlib = os.path.join(pylib_loc, pylib_ldlibrary)
+    if os.path.exists(py_sharedlib):
         return pylib_loc
 
     return "None"