From 02da0c9ba5c2bea2a25d6172322ea4d5801a8c55 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Wed, 1 Mar 2017 17:16:37 +0000
Subject: [PATCH 1/5] conda: Unbundle libxgboost.{dll,dylib,so}

.. and put libxgboost.{dylib,so} into $PREFIX/lib/
.. and libxgboost.dll into $PREFIX/Library/mingw-w64/lib/
---
 python-package/setup.py           | 19 ++++++++-----------
 python-package/xgboost/libpath.py |  4 ++++
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/python-package/setup.py b/python-package/setup.py
index d4b6aa6b..716bee8a 100644
--- a/python-package/setup.py
+++ b/python-package/setup.py
@@ -16,16 +16,13 @@ libpath_py = os.path.join(CURRENT_DIR, 'xgboost/libpath.py')
 libpath = {'__file__': libpath_py}
 exec(compile(open(libpath_py, "rb").read(), libpath_py, 'exec'), libpath, libpath)
 
-LIB_PATH = []
-for libfile in libpath['find_lib_path']():
-    try:
-        relpath = os.path.relpath(libfile, CURRENT_DIR)
-        LIB_PATH.append(relpath)
-        break  # need only one
-    except ValueError:
-        continue
-
-print("Install libxgboost from: %s" % LIB_PATH)
+LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
+if os.getenv('CONDA_BUILD'):
+    print("Conda-build detected, not installing (xgboost nor) libxgboost from: %s" % LIB_PATH)
+    data_files=('xgboost')
+else:
+    print("Install libxgboost from: %s" % LIB_PATH)
+    data_files=('xgboost', LIB_PATH)
 # Please use setup_pip.py for generating and deploying pip installation
 # detailed instruction in setup_pip.py
 setup(name='xgboost',
@@ -43,7 +40,7 @@ setup(name='xgboost',
       # this will use MANIFEST.in during install where we specify additional files,
       # this is the golden line
       include_package_data=True,
-      data_files=[('xgboost', LIB_PATH)],
+      data_files=[data_files],
       license='Apache-2.0',
       classifiers=['License :: OSI Approved :: Apache Software License'],
       url='https://github.com/dmlc/xgboost')
diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py
index d87922c0..8158b5a0 100644
--- a/python-package/xgboost/libpath.py
+++ b/python-package/xgboost/libpath.py
@@ -24,6 +24,10 @@ def find_lib_path():
     dll_path = [curr_path, os.path.join(curr_path, '../../lib/'),
                 os.path.join(curr_path, './lib/'),
                 os.path.join(sys.prefix, 'xgboost')]
+    if sys.platform == 'win32':
+        dll_path = [os.path.join(sys.prefix, 'Library', 'mingw-w64', 'bin')]
+    else:
+        dll_path = [os.path.join(sys.prefix, 'lib')]
     if sys.platform == 'win32':
         if platform.architecture()[0] == '64bit':
             dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/'))
-- 
2.18.0

