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

3
if [[ $TRAVIS_OS_NAME == "osx" ]]; then
4
5
    export CXX=g++-8
    export CC=gcc-8
6
7
8
9
fi

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

wxchan's avatar
wxchan committed
11
12
cd $TRAVIS_BUILD_DIR

13
if [[ $TASK == "check-docs" ]]; then
14
    if [[ $PYTHON_VERSION == "2.7" ]]; then
15
16
        conda install mock
    fi
17
    conda install sphinx "sphinx_rtd_theme>=0.3"  # html5validator
18
    pip install rstcheck
19
    # check reStructuredText formatting
20
    cd $TRAVIS_BUILD_DIR/python-package
21
    rstcheck --report warning `find . -type f -name "*.rst"` || exit -1
22
    cd $TRAVIS_BUILD_DIR/docs
23
    rstcheck --report warning --ignore-directives=autoclass,autofunction `find . -type f -name "*.rst"` || exit -1
24
    # build docs and check them for broken links
25
    make html || exit -1
26
    find ./_build/html/ -type f -name '*.html' -exec \
27
    sed -i'.bak' -e 's;\(\.\/[^.]*\.\)rst\([^[:space:]]*\);\1html\2;g' {} \;  # emulate js function
28
#    html5validator --root ./_build/html/ || exit -1
29
    if [[ $TRAVIS_OS_NAME != "osx" ]]; then
30
        sudo apt-get install linkchecker
31
32
        linkchecker --config=.linkcheckerrc ./_build/html/*.html || exit -1
    fi
33
34
35
36
37
38
    # 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
39
40
41
    exit 0
fi

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

48
if [[ $TASK == "if-else" ]]; then
49
    conda install numpy
50
    mkdir $TRAVIS_BUILD_DIR/build && cd $TRAVIS_BUILD_DIR/build && cmake .. && make lightgbm || exit -1
wxchan's avatar
wxchan committed
51
    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
52
53
54
55
56
    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

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

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

76
if [[ $TASK == "gpu" ]]; then
77
    conda install --yes -c conda-forge boost
78
    sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "gpu";/' $TRAVIS_BUILD_DIR/include/LightGBM/config.h
79
    grep -q 'std::string device_type = "gpu"' $TRAVIS_BUILD_DIR/include/LightGBM/config.h || exit -1  # make sure that changes were really done
80
    if [[ $METHOD == "pip" ]]; then
Guolin Ke's avatar
Guolin Ke committed
81
        cd $TRAVIS_BUILD_DIR/python-package && python setup.py sdist || exit -1
82
        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/include/" || exit -1
83
        pytest $TRAVIS_BUILD_DIR/tests/python_package_test || exit -1
84
85
        exit 0
    fi
wxchan's avatar
wxchan committed
86
87
fi

88
mkdir $TRAVIS_BUILD_DIR/build && cd $TRAVIS_BUILD_DIR/build
wxchan's avatar
wxchan committed
89

90
if [[ $TASK == "mpi" ]]; then
91
    cd $TRAVIS_BUILD_DIR/python-package && python setup.py sdist || exit -1
92
    pip install $TRAVIS_BUILD_DIR/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1
93
    cd $TRAVIS_BUILD_DIR/build
wxchan's avatar
wxchan committed
94
    cmake -DUSE_MPI=ON ..
95
96
elif [[ $TASK == "gpu" ]]; then
    cmake -DUSE_GPU=ON -DBOOST_ROOT=$HOME/miniconda/envs/test-env/ -DOpenCL_INCLUDE_DIR=$AMDAPPSDK/include/ ..
wxchan's avatar
wxchan committed
97
98
99
100
101
102
103
else
    cmake ..
fi

make _lightgbm || exit -1

cd $TRAVIS_BUILD_DIR/python-package && python setup.py install --precompile || exit -1
104
pytest $TRAVIS_BUILD_DIR || exit -1
105

106
if [[ $TASK == "regular" ]]; then
107
108
109
110
111
112
    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
    for f in *.py; do python $f || exit -1; done  # run all examples
113
fi