test.sh 7.06 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
#!/bin/bash

3
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "gcc" ]]; then
4
5
    export CXX=g++-8
    export CC=gcc-8
6
elif [[ $OS_NAME == "linux" ]] && [[ $COMPILER == "clang" ]]; then
7
8
    export CXX=clang++
    export CC=clang
Guolin Ke's avatar
Guolin Ke committed
9
10
fi

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
if [[ $TRAVIS == "true" ]]; then
    conda create -q -y -n $CONDA_ENV python=$PYTHON_VERSION
    source activate $CONDA_ENV
fi

cd $BUILD_DIRECTORY

if [[ $TRAVIS == "true" ]] && [[ $TASK == "check-docs" ]]; then
    if [[ $PYTHON_VERSION == "2.7" ]]; then
        conda -y -n $CONDA_ENV mock
    fi
    conda install -y -n $CONDA_ENV sphinx "sphinx_rtd_theme>=0.3"  # html5validator
    pip install rstcheck
    # check reStructuredText formatting
    cd $BUILD_DIRECTORY/python-package
    rstcheck --report warning `find . -type f -name "*.rst"` || exit -1
    cd $BUILD_DIRECTORY/docs
    rstcheck --report warning --ignore-directives=autoclass,autofunction `find . -type f -name "*.rst"` || exit -1
    # build docs and check them for broken links
    make html || exit -1
    find ./_build/html/ -type f -name '*.html' -exec \
    sed -i'.bak' -e 's;\(\.\/[^.]*\.\)rst\([^[:space:]]*\);\1html\2;g' {} \;  # emulate js function
#    html5validator --root ./_build/html/ || exit -1
    if [[ $OS_NAME == "linux" ]]; then
        sudo apt-get install linkchecker
        linkchecker --config=.linkcheckerrc ./_build/html/*.html || exit -1
    fi
    # check the consistency of parameters' descriptions and other stuff
    cp $BUILD_DIRECTORY/docs/Parameters.rst $BUILD_DIRECTORY/docs/Parameters-backup.rst
    cp $BUILD_DIRECTORY/src/io/config_auto.cpp $BUILD_DIRECTORY/src/io/config_auto-backup.cpp
    python $BUILD_DIRECTORY/helper/parameter_generator.py || exit -1
    diff $BUILD_DIRECTORY/docs/Parameters-backup.rst $BUILD_DIRECTORY/docs/Parameters.rst || exit -1
    diff $BUILD_DIRECTORY/src/io/config_auto-backup.cpp $BUILD_DIRECTORY/src/io/config_auto.cpp || exit -1
    exit 0
fi
46

Guolin Ke's avatar
Guolin Ke committed
47
48
49
50
51
52
53
54
if [[ $TASK == "pylint" ]]; then
    conda install -y -n $CONDA_ENV pycodestyle
    pycodestyle --ignore=E501,W503 --exclude=./compute,./docs,./.nuget . || exit -1
    exit 0
fi

if [[ $TASK == "if-else" ]]; then
    conda install -y -n $CONDA_ENV numpy
55
56
57
58
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build && cmake .. && make lightgbm || exit -1
    cd $BUILD_DIRECTORY/tests/cpp_test && ../../lightgbm config=train.conf convert_model_language=cpp convert_model=../../src/boosting/gbdt_prediction.cpp && ../../lightgbm config=predict.conf output_result=origin.pred || exit -1
    cd $BUILD_DIRECTORY/build && make lightgbm || exit -1
    cd $BUILD_DIRECTORY/tests/cpp_test && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit -1
Guolin Ke's avatar
Guolin Ke committed
59
60
61
62
63
    exit 0
fi

conda install -q -y -n $CONDA_ENV numpy nose scipy scikit-learn pandas matplotlib python-graphviz pytest

64
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then
65
66
67
    ln -sf `ls -d "$(brew --cellar libomp)"/*/lib`/* $CONDA_PREFIX/lib || exit -1  # fix "OMP: Error #15: Initializing libiomp5.dylib, but found libomp.dylib already initialized." (OpenMP library conflict due to conda's MKL)
fi

Guolin Ke's avatar
Guolin Ke committed
68
if [[ $TASK == "sdist" ]]; then
69
70
71
72
73
74
    cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
    pip install $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v || exit -1
    if [[ $AZURE == "true" ]]; then
        cp $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz $BUILD_ARTIFACTSTAGINGDIRECTORY
    fi
    pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
Guolin Ke's avatar
Guolin Ke committed
75
76
    exit 0
elif [[ $TASK == "bdist" ]]; then
77
78
79
80
81
82
    if [[ $OS_NAME == "macos" ]]; then
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --universal || exit -1
        mv dist/lightgbm-$LGB_VER-py2.py3-none-macosx.whl dist/lightgbm-$LGB_VER-py2.py3-none-macosx_10_6_x86_64.macosx_10_7_x86_64.macosx_10_8_x86_64.macosx_10_9_x86_64.macosx_10_10_x86_64.macosx_10_11_x86_64.macosx_10_12_x86_64.macosx_10_13_x86_64.whl
        if [[ $AZURE == "true" ]]; then
            cp dist/lightgbm-$LGB_VER-py2.py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
        fi
Guolin Ke's avatar
Guolin Ke committed
83
    else
84
85
86
87
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=manylinux1_x86_64 --universal || exit -1
        if [[ $AZURE == "true" ]]; then
            cp dist/lightgbm-$LGB_VER-py2.py3-none-manylinux1_x86_64.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
        fi
Guolin Ke's avatar
Guolin Ke committed
88
    fi
89
90
    pip install $BUILD_DIRECTORY/python-package/dist/*.whl || exit -1
    pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
91
92
93
94
    exit 0
fi

if [[ $TASK == "gpu" ]]; then
95
96
97
98
99
    if [[ $TRAVIS == "true" ]]; then
        conda install -y -n $CONDA_ENV -c conda-forge boost
    fi
    sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' $BUILD_DIRECTORY/include/LightGBM/config.h
    grep -q 'std::string device_type = "gpu"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1  # make sure that changes were really done
Guolin Ke's avatar
Guolin Ke committed
100
    if [[ $METHOD == "pip" ]]; then
101
102
103
104
105
106
107
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
        if [[ $AZURE == "true" ]]; then
            pip install $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu --install-option="--opencl-include-dir=$AMDAPPSDK_PATH/include/" || exit -1
        else
            pip install $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu --install-option="--boost-root=$CONDA_PREFIX" --install-option="--opencl-include-dir=$AMDAPPSDK_PATH/include/" || exit -1
        fi
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
Guolin Ke's avatar
Guolin Ke committed
108
109
110
111
        exit 0
    fi
fi

112
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
Guolin Ke's avatar
Guolin Ke committed
113
114

if [[ $TASK == "mpi" ]]; then
115
    if [[ $METHOD == "pip" ]]; then
116
117
118
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
        pip install $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
119
120
        exit 0
    fi
Guolin Ke's avatar
Guolin Ke committed
121
122
    cmake -DUSE_MPI=ON ..
elif [[ $TASK == "gpu" ]]; then
123
124
125
126
127
    if [[ $AZURE == "true" ]]; then
        cmake -DUSE_GPU=ON -DOpenCL_INCLUDE_DIR=$AMDAPPSDK_PATH/include/ ..
    else
        cmake -DUSE_GPU=ON -DBOOST_ROOT=$CONDA_PREFIX -DOpenCL_INCLUDE_DIR=$AMDAPPSDK_PATH/include/ ..
    fi
Guolin Ke's avatar
Guolin Ke committed
128
129
130
131
132
133
else
    cmake ..
fi

make _lightgbm || exit -1

134
135
cd $BUILD_DIRECTORY/python-package && python setup.py install --precompile || exit -1
pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
136
137

if [[ $TASK == "regular" ]]; then
138
139
140
141
142
143
    if [[ $AZURE == "true" ]]; then
        if [[ $OS_NAME == "macos" ]]; then
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.dylib
        else
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.so
        fi
Guolin Ke's avatar
Guolin Ke committed
144
    fi
145
    cd $BUILD_DIRECTORY/examples/python-guide
Guolin Ke's avatar
Guolin Ke committed
146
147
148
149
    sed -i'.bak' '/import lightgbm as lgb/a\
import matplotlib\
matplotlib.use\(\"Agg\"\)\
' plot_example.py  # prevent interactive window mode
150
    sed -i'.bak' 's/graph.render(view=True)/graph.render(view=False)/' plot_example.py
Guolin Ke's avatar
Guolin Ke committed
151
152
    for f in *.py; do python $f || exit -1; done  # run all examples
fi