test.sh 5.77 KB
Newer Older
1
#!/bin/bash
wxchan's avatar
wxchan committed
2

3
if [[ $TRAVIS_OS_NAME == "osx" ]] && [[ $COMPILER == "gcc" ]]; then
4
5
    export CXX=g++-8
    export CC=gcc-8
6
7
8
elif [[ $TRAVIS_OS_NAME == "linux" ]] && [[ $COMPILER == "clang" ]]; then
    export CXX=clang++
    export CC=clang
9
10
11
12
fi

conda create -q -n test-env python=$PYTHON_VERSION
source activate test-env
13

wxchan's avatar
wxchan committed
14
15
cd $TRAVIS_BUILD_DIR

16
if [[ $TASK == "check-docs" ]]; then
17
    if [[ $PYTHON_VERSION == "2.7" ]]; then
18
19
        conda install mock
    fi
20
    conda install sphinx "sphinx_rtd_theme>=0.3"  # html5validator
21
    pip install rstcheck
22
    # check reStructuredText formatting
23
    cd $TRAVIS_BUILD_DIR/python-package
24
    rstcheck --report warning `find . -type f -name "*.rst"` || exit -1
25
    cd $TRAVIS_BUILD_DIR/docs
26
    rstcheck --report warning --ignore-directives=autoclass,autofunction `find . -type f -name "*.rst"` || exit -1
27
    # build docs and check them for broken links
28
    make html || exit -1
29
    find ./_build/html/ -type f -name '*.html' -exec \
30
    sed -i'.bak' -e 's;\(\.\/[^.]*\.\)rst\([^[:space:]]*\);\1html\2;g' {} \;  # emulate js function
31
#    html5validator --root ./_build/html/ || exit -1
32
    if [[ $TRAVIS_OS_NAME == "linux" ]]; then
33
        sudo apt-get install linkchecker
34
35
        linkchecker --config=.linkcheckerrc ./_build/html/*.html || exit -1
    fi
36
37
38
39
40
41
    # check the consistency of parameters' descriptions and other stuff
    cp $TRAVIS_BUILD_DIR/docs/Parameters.rst $TRAVIS_BUILD_DIR/docs/Parameters-backup.rst
    cp $TRAVIS_BUILD_DIR/src/io/config_auto.cpp $TRAVIS_BUILD_DIR/src/io/config_auto-backup.cpp
    python $TRAVIS_BUILD_DIR/helper/parameter_generator.py || exit -1
    diff $TRAVIS_BUILD_DIR/docs/Parameters-backup.rst $TRAVIS_BUILD_DIR/docs/Parameters.rst || exit -1
    diff $TRAVIS_BUILD_DIR/src/io/config_auto-backup.cpp $TRAVIS_BUILD_DIR/src/io/config_auto.cpp || exit -1
42
43
44
    exit 0
fi

45
if [[ $TASK == "pylint" ]]; then
46
47
    conda install pycodestyle
    pycodestyle --ignore=E501,W503 --exclude=./compute,./docs,./.nuget . || exit -1
wxchan's avatar
wxchan committed
48
49
50
    exit 0
fi

51
if [[ $TASK == "if-else" ]]; then
52
    conda install numpy
53
    mkdir $TRAVIS_BUILD_DIR/build && cd $TRAVIS_BUILD_DIR/build && cmake .. && make lightgbm || exit -1
wxchan's avatar
wxchan committed
54
    cd $TRAVIS_BUILD_DIR/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
wxchan's avatar
wxchan committed
55
56
57
58
59
    cd $TRAVIS_BUILD_DIR/build && make lightgbm || exit -1
    cd $TRAVIS_BUILD_DIR/tests/cpp_test && ../../lightgbm config=predict.conf output_result=ifelse.pred && python test.py || exit -1
    exit 0
fi

60
conda install numpy nose scipy scikit-learn pandas matplotlib python-graphviz pytest
wxchan's avatar
wxchan committed
61

62
63
64
65
if [[ $TRAVIS_OS_NAME == "osx" ]] && [[ $COMPILER == "clang" ]]; then
    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

66
if [[ $TASK == "sdist" ]]; then
wxchan's avatar
wxchan committed
67
    cd $TRAVIS_BUILD_DIR/python-package && python setup.py sdist || exit -1
68
    pip install $TRAVIS_BUILD_DIR/python-package/dist/lightgbm-$LGB_VER.tar.gz -v || exit -1
69
    pytest $TRAVIS_BUILD_DIR/tests/python_package_test || exit -1
70
    exit 0
71
elif [[ $TASK == "bdist" ]]; then
Guolin Ke's avatar
Guolin Ke committed
72
73
    if [[ $TRAVIS_OS_NAME == "osx" ]]; then
        cd $TRAVIS_BUILD_DIR/python-package && python setup.py bdist_wheel --plat-name=macosx --universal || exit -1
74
        mv dist/lightgbm-$LGB_VER-py2.py3-none-macosx.whl dist/lightgbm-$LGB_VER-py2.py3-none-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
Guolin Ke's avatar
Guolin Ke committed
75
76
77
    else
        cd $TRAVIS_BUILD_DIR/python-package && python setup.py bdist_wheel --plat-name=manylinux1_x86_64 --universal || exit -1
    fi
78
    pip install $TRAVIS_BUILD_DIR/python-package/dist/*.whl || exit -1
79
    pytest $TRAVIS_BUILD_DIR/tests || exit -1
wxchan's avatar
wxchan committed
80
81
82
    exit 0
fi

83
if [[ $TASK == "gpu" ]]; then
84
    conda install --yes -c conda-forge boost
85
    sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' $TRAVIS_BUILD_DIR/include/LightGBM/config.h
86
    grep -q 'std::string device_type = "gpu"' $TRAVIS_BUILD_DIR/include/LightGBM/config.h || exit -1  # make sure that changes were really done
87
    if [[ $METHOD == "pip" ]]; then
Guolin Ke's avatar
Guolin Ke committed
88
        cd $TRAVIS_BUILD_DIR/python-package && python setup.py sdist || exit -1
89
        pip install $TRAVIS_BUILD_DIR/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu --install-option="--boost-root=$HOME/miniconda/envs/test-env/" --install-option="--opencl-include-dir=$AMDAPPSDK_PATH/include/" || exit -1
90
        pytest $TRAVIS_BUILD_DIR/tests/python_package_test || exit -1
91
92
        exit 0
    fi
wxchan's avatar
wxchan committed
93
94
fi

95
mkdir $TRAVIS_BUILD_DIR/build && cd $TRAVIS_BUILD_DIR/build
wxchan's avatar
wxchan committed
96

97
if [[ $TASK == "mpi" ]]; then
98
99
100
101
102
103
    if [[ $METHOD == "pip" ]]; then
        cd $TRAVIS_BUILD_DIR/python-package && python setup.py sdist || exit -1
        pip install $TRAVIS_BUILD_DIR/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1
        pytest $TRAVIS_BUILD_DIR/tests/python_package_test || exit -1
        exit 0
    fi
wxchan's avatar
wxchan committed
104
    cmake -DUSE_MPI=ON ..
105
elif [[ $TASK == "gpu" ]]; then
106
    cmake -DUSE_GPU=ON -DBOOST_ROOT=$HOME/miniconda/envs/test-env/ -DOpenCL_INCLUDE_DIR=$AMDAPPSDK_PATH/include/ ..
wxchan's avatar
wxchan committed
107
108
109
110
111
112
113
else
    cmake ..
fi

make _lightgbm || exit -1

cd $TRAVIS_BUILD_DIR/python-package && python setup.py install --precompile || exit -1
114
pytest $TRAVIS_BUILD_DIR/tests || exit -1
115

116
if [[ $TASK == "regular" ]]; then
117
118
119
120
121
    cd $TRAVIS_BUILD_DIR/examples/python-guide
    sed -i'.bak' '/import lightgbm as lgb/a\
import matplotlib\
matplotlib.use\(\"Agg\"\)\
' plot_example.py  # prevent interactive window mode
122
    sed -i'.bak' 's/graph.render(view=True)/graph.render(view=False)/' plot_example.py
123
    for f in *.py; do python $f || exit -1; done  # run all examples
124
fi