Description: Improve detection of compiled extension
 The original code cannot detect the library if the package is not installed,
 which prevents running the unit tests at build time.
 Changes were also necessary for python to be able to find the compiled
 extension after pybuild renames it with the multiarch triplet.
Author: Afif Elghraoui <afif@debian.org>
Forwarded: no
Last-Update: 2016-07-02

--- kineticstools.orig/kineticsTools/ipdModel.py
+++ kineticstools/kineticsTools/ipdModel.py
@@ -34,8 +34,8 @@
 import h5py
 import numpy as np
 import ctypes as C
+import sysconfig
 from kineticsTools.sharedArray import SharedArray
-from pkg_resources import Requirement, resource_filename
 
 byte = np.dtype('byte')
 float32 = np.dtype('float32')
@@ -67,9 +67,6 @@
 
 codeToBase = dict([(y, x) for (x, y) in baseToCode.items()])
 
-def _getAbsPath(fname):
-    return resource_filename(Requirement.parse('kineticsTools'),'kineticsTools/%s' % fname)
-
 class GbmContextModel(object):
 
     """
@@ -156,23 +153,16 @@
 
         import platform
 
-        if platform.system() == "Windows":
+        path = os.path.dirname(os.path.abspath(__file__))
+        libbasename = "tree_predict"
 
-            libfn = "tree_predict.dll"
-            path = os.path.dirname(os.path.abspath(__file__))
-            windowsLib = path + os.path.sep + libfn
-
-            if os.path.exists(windowsLib):
-                self._lib = np.ctypeslib.load_library(libfn, path)
-            else:
-                raise Exception("can't find tree_predict.dll")
+        multiarch_lib = '.'.join([libbasename,
+                                  sysconfig.get_config_var('MULTIARCH'),
+                                  'so'])
+        if os.path.exists(path + os.path.sep + multiarch_lib):
+            self._lib = np.ctypeslib.load_library(multiarch_lib, path)
         else:
-            DLL_PATH = _getAbsPath("tree_predict.so")
-
-            if os.path.exists(DLL_PATH):
-                self._lib = np.ctypeslib.load_library("tree_predict.so", DLL_PATH)
-            else:
-                raise Exception("can't find tree_predict.so")
+            self._lib = np.ctypeslib.load_library(libbasename, path)
 
         lpb = self._lib
 
