Repository: numpy/numpy

Issue:
distutils.misc_util.get_shared_lib_extension(is_python_ext=False) returns _d.so with python-dbg
distutils.misc_util.get_shared_lib_extension(is_python_ext=False) returns _d.so with python-dbg
with numpy 1.7.0 on debian unstable and numpy 1.8.0.dev-0934653 ubuntu 12.10

is this really intentional?
I would have though is_python_ext=False gets me the the regular library extension which is just .so on linux.
If not the documentation should make this clear.



Discussion:
interestingly python3-dbg returns .so correctly (on ubuntu 13.04, python2-dbg is also wrong there)


Resolving patch:
diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py
--- a/numpy/distutils/misc_util.py
+++ b/numpy/distutils/misc_util.py
@@ -605,11 +605,29 @@ def get_shared_lib_extension(is_python_ext=False):
     Linux, but not on OS X.
 
     """
-    so_ext = distutils.sysconfig.get_config_var('SO') or ''
-    # fix long extension for Python >=3.2, see PEP 3149.
-    if (not is_python_ext) and 'SOABI' in distutils.sysconfig.get_config_vars():
-        # Does nothing unless SOABI config var exists
-        so_ext = so_ext.replace('.' + distutils.sysconfig.get_config_var('SOABI'), '', 1)
+    confvars = distutils.sysconfig.get_config_vars()
+    # SO is deprecated in 3.3.1, use EXT_SUFFIX instead
+    so_ext = confvars.get('EXT_SUFFIX', None)
+    if so_ext is None:
+        so_ext = confvars.get('SO', '')
+
+    if not is_python_ext:
+        # hardcode known values, config vars (including SHLIB_SUFFIX) are
+        # unreliable (see #3182)
+        # darwin, windows and debug linux are wrong in 3.3.1 and older
+        if (sys.platform.startswith('linux') or
+            sys.platform.startswith('gnukfreebsd')):
+            so_ext = '.so'
+        elif sys.platform.startswith('darwin'):
+            so_ext = '.dylib'
+        elif sys.platform.startswith('win'):
+            so_ext = '.dll'
+        else:
+            # fall back to config vars for unknown platforms
+            # fix long extension for Python >=3.2, see PEP 3149.
+            if 'SOABI' in confvars:
+                # Does nothing unless SOABI config var exists
+                so_ext = so_ext.replace('.' + confvars.get('SOABI'), '', 1)
 
     return so_ext
 


Test patch:
diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py
--- a/numpy/distutils/tests/test_misc_util.py
+++ b/numpy/distutils/tests/test_misc_util.py
@@ -2,7 +2,8 @@
 from __future__ import division, absolute_import, print_function
 
 from numpy.testing import *
-from numpy.distutils.misc_util import appendpath, minrelpath, gpaths, rel_path
+from numpy.distutils.misc_util import appendpath, minrelpath, \
+    gpaths, get_shared_lib_extension
 from os.path import join, sep, dirname
 
 ajoin = lambda *paths: join(*((sep,)+paths))
@@ -54,6 +55,21 @@ def test_gpaths(self):
         f = gpaths('system_info.py', local_path)
         assert_(join(local_path,'system_info.py')==f[0],repr(f))
 
+class TestSharedExtension(TestCase):
+
+    def test_get_shared_lib_extension(self):
+        import sys
+        ext = get_shared_lib_extension(is_python_ext=False)
+        if sys.platform.startswith('linux'):
+            assert_equal(ext, '.so')
+        elif sys.platform.startswith('gnukfreebsd'):
+            assert_equal(ext, '.so')
+        elif sys.platform.startswith('darwin'):
+            assert_equal(ext, '.dylib')
+        elif sys.platform.startswith('win'):
+            assert_equal(ext, '.dll')
+        # just check for no crash
+        assert_(get_shared_lib_extension(is_python_ext=True))
 
 if __name__ == "__main__":
     run_module_suite()