From 74dcba4e5eea6031b5002d22a02db12293b3bd0b 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 d9ef113c..5edb8e23 100644
--- a/python-package/setup.py
+++ b/python-package/setup.py
@@ -17,16 +17,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',
@@ -44,7 +41,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',
                    'Development Status :: 5 - Production/Stable',
diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py
index 4d276050..e4899989 100644
--- a/python-package/xgboost/libpath.py
+++ b/python-package/xgboost/libpath.py
@@ -23,6 +23,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.17.1

