diff --git a/Makefile b/Makefile index c9e35e80c..c790f6b72 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ export CC = gcc +#build on the fly export CXX = g++ export MPICXX = mpicxx export LDFLAGS= -pthread -lm @@ -167,6 +168,30 @@ Rcheck: make Rbuild R CMD check --as-cran xgboost*.tar.gz +pythonpack: + #make clean + cd subtree/rabit;make clean;cd .. + rm -rf xgboost-deploy xgboost*.tar.gz + cp -r python-package xgboost-deploy + cp *.md xgboost-deploy/ + cp LICENSE xgboost-deploy/ + cp Makefile xgboost-deploy/xgboost + cp -r wrapper xgboost-deploy/xgboost + cp -r subtree xgboost-deploy/xgboost + cp -r multi-node xgboost-deploy/xgboost + cp -r windows xgboost-deploy/xgboost + cp -r src xgboost-deploy/xgboost + + #make python + +pythonbuild: + make pythonpack + python setup.py install + +pythoncheck: + make pythonbuild + python -c 'import xgboost;print xgboost.core.find_lib_path()' + # lint requires dmlc to be in current folder lint: dmlc-core/scripts/lint.py xgboost $(LINT_LANG) src wrapper R-package python-package diff --git a/python-package/MANIFEST.in b/python-package/MANIFEST.in new file mode 100644 index 000000000..2d93429a9 --- /dev/null +++ b/python-package/MANIFEST.in @@ -0,0 +1,7 @@ +include *.sh *.md +recursive-include xgboost * +recursive-include xgboost/wrapper * +recursive-include xgboost/windows * +recursive-include xgboost/subtree * +recursive-include xgboost/src * +recursive-include xgboost/multi-node * diff --git a/python-package/setup.cfg b/python-package/setup.cfg new file mode 100644 index 000000000..b88034e41 --- /dev/null +++ b/python-package/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md diff --git a/python-package/setup.py b/python-package/setup.py index 42e39f3ba..e33e28fdc 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -2,20 +2,41 @@ """Setup xgboost package.""" from __future__ import absolute_import import sys -from setuptools import setup +from setuptools import setup,find_packages +import subprocess sys.path.insert(0, '.') +#build on the fly + +build_sh = subprocess.Popen(['sh','xgboost/build-python.sh']) +build_sh.wait() +output = build_sh.communicate() +print output + import xgboost LIB_PATH = xgboost.core.find_lib_path() +#print LIB_PATH +#to deploy to pip, please use +#make pythonpack +#python setup.py register sdist upload +#and be sure to test it firstly using "python setup.py register sdist upload -r pypitest" setup(name='xgboost', version=xgboost.__version__, + #version='0.4a12', description=xgboost.__doc__, install_requires=[ 'numpy', 'scipy', ], + maintainer = 'Hongliang Liu', + maintainer_email = 'phunter.lau@gmail.com', zip_safe=False, - packages=['xgboost'], - data_files=[('xgboost', [LIB_PATH[0]])], + packages = find_packages(), + #package_dir = {'':'xgboost'}, #don't need this and don't use this, give everything to MANIFEST.in + #package_data = {'': ['*.txt','*.md','*.sh'], + # } + include_package_data=True, #this will use MANIFEST.in during install where we specify additional files, this is the golden line + data_files=[('xgboost',LIB_PATH), + ], url='https://github.com/dmlc/xgboost') diff --git a/python-package/xgboost/build-python.sh b/python-package/xgboost/build-python.sh new file mode 100755 index 000000000..398b076b8 --- /dev/null +++ b/python-package/xgboost/build-python.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# This is a simple script to make xgboost in MAC and Linux for python wrapper only +# Basically, it first try to make with OpenMP, if fails, disable OpenMP and make it again. +# This will automatically make xgboost for MAC users who don't have OpenMP support. +# In most cases, type make will give what you want. + +# See additional instruction in doc/build.md + +# note: this script is build for python package only, and it might have some filename +# conflict with build.sh which is for everything. + + +pushd xgboost +if make python; then + echo "Successfully build multi-thread xgboost" +else + echo "-----------------------------" + echo "Building multi-thread xgboost failed" + echo "Start to build single-thread xgboost" + make clean + make python no_omp=1 + echo "Successfully build single-thread xgboost" + echo "If you want multi-threaded version" + echo "See additional instructions in doc/build.md" +fi +popd diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 0849d276c..ff95b33fb 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -39,7 +39,8 @@ def find_lib_path(): List of all found library path to xgboost """ curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) - dll_path = [curr_path, os.path.join(curr_path, '../../wrapper/')] + #make pythonpack hack: copy this directory one level upper for setup.py + dll_path = [curr_path, os.path.join(curr_path, '../../wrapper/'),os.path.join(curr_path, './wrapper/')] if os.name == 'nt': if platform.architecture()[0] == '64bit': dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/'))