test.sh 8.33 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
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]] && [[ $(sw_vers -productVersion | cut -d'.' -f2) -ge "14" ]]; then
    CMAKE_OPTS=(-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include"
                -DOpenMP_C_LIB_NAMES=omp
                -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include"
                -DOpenMP_CXX_LIB_NAMES=omp
                -DOpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib)
else
    CMAKE_OPTS=()
fi

21
22
23
24
25
26
27
28
29
30
31
32
33
if [[ $AZURE == "true" ]] && [[ $OS_NAME == "linux" ]] && [[ $TASK == "swig" ]]; then
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build
    cmake -DUSE_SWIG=ON "${CMAKE_OPTS[@]}" ..
    make -j4 || exit -1
    if [[ $COMPILER == "gcc" ]]; then
        objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit -1
        objdump -T $BUILD_DIRECTORY/lib_lightgbm_swig.so >> $BUILD_DIRECTORY/objdump.log || exit -1
        python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit -1
    fi
    cp $BUILD_DIRECTORY/build/lightgbmlib.jar $BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib.jar
    exit 0
fi

34
35
conda create -q -y -n $CONDA_ENV python=$PYTHON_VERSION
source activate $CONDA_ENV
36
37
38
39
40

cd $BUILD_DIRECTORY

if [[ $TRAVIS == "true" ]] && [[ $TASK == "check-docs" ]]; then
    if [[ $PYTHON_VERSION == "2.7" ]]; then
Nikita Titov's avatar
Nikita Titov committed
41
        conda -q -y -n $CONDA_ENV mock
42
    fi
Nikita Titov's avatar
Nikita Titov committed
43
    conda install -q -y -n $CONDA_ENV sphinx "sphinx_rtd_theme>=0.3"
44
    pip install --user rstcheck
45
46
47
48
49
50
51
52
53
54
    # 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
    if [[ $OS_NAME == "linux" ]]; then
55
        sudo apt-get update
56
57
58
59
60
61
        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
62
    python $BUILD_DIRECTORY/helpers/parameter_generator.py || exit -1
63
64
65
66
    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
67

Guolin Ke's avatar
Guolin Ke committed
68
if [[ $TASK == "pylint" ]]; then
Nikita Titov's avatar
Nikita Titov committed
69
    conda install -q -y -n $CONDA_ENV pycodestyle pydocstyle
70
    pycodestyle --ignore=E501,W503 --exclude=./compute,./.nuget . || exit -1
71
    pydocstyle --convention=numpy --add-ignore=D105 --match-dir="^(?!^compute|test|example).*" --match="(?!^test_|setup).*\.py" . || exit -1
Guolin Ke's avatar
Guolin Ke committed
72
73
74
75
    exit 0
fi

if [[ $TASK == "if-else" ]]; then
Nikita Titov's avatar
Nikita Titov committed
76
    conda install -q -y -n $CONDA_ENV numpy
77
    mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build && cmake "${CMAKE_OPTS[@]}" .. && make lightgbm -j4 || exit -1
78
    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
79
    cd $BUILD_DIRECTORY/build && make lightgbm -j4 || exit -1
80
    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
81
82
83
    exit 0
fi

84
conda install -q -y -n $CONDA_ENV matplotlib nose numpy pandas psutil pytest python-graphviz scikit-learn scipy
Guolin Ke's avatar
Guolin Ke committed
85

86
if [[ $OS_NAME == "macos" ]] && [[ $COMPILER == "clang" ]]; then
87
    sudo 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)
88
89
fi

Guolin Ke's avatar
Guolin Ke committed
90
if [[ $TASK == "sdist" ]]; then
91
    cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
92
    pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v || exit -1
93
94
95
96
    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
97
98
    exit 0
elif [[ $TASK == "bdist" ]]; then
99
100
    if [[ $OS_NAME == "macos" ]]; then
        cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --universal || exit -1
101
        mv dist/lightgbm-$LGB_VER-py2.py3-none-macosx.whl dist/lightgbm-$LGB_VER-py2.py3-none-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.macosx_10_14_x86_64.whl
102
103
104
        if [[ $AZURE == "true" ]]; then
            cp dist/lightgbm-$LGB_VER-py2.py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY
        fi
Guolin Ke's avatar
Guolin Ke committed
105
    else
106
107
108
109
        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
110
    fi
111
    pip install --user $BUILD_DIRECTORY/python-package/dist/*.whl || exit -1
112
    pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
113
114
115
    exit 0
fi

116
117
mkdir $BUILD_DIRECTORY/build && cd $BUILD_DIRECTORY/build

Guolin Ke's avatar
Guolin Ke committed
118
if [[ $TASK == "gpu" ]]; then
119
120
    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
121
    if [[ $METHOD == "pip" ]]; then
122
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
123
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu --install-option="--opencl-include-dir=$AMDAPPSDK_PATH/include/" || exit -1
124
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
Guolin Ke's avatar
Guolin Ke committed
125
126
        exit 0
    fi
127
    cmake -DUSE_GPU=ON -DOpenCL_INCLUDE_DIR=$AMDAPPSDK_PATH/include/ "${CMAKE_OPTS[@]}" ..
128
elif [[ $TASK == "mpi" ]]; then
129
    if [[ $METHOD == "pip" ]]; then
130
        cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
131
        pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1
132
        pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
133
134
        exit 0
    fi
135
    cmake -DUSE_MPI=ON "${CMAKE_OPTS[@]}" ..
Guolin Ke's avatar
Guolin Ke committed
136
else
137
    cmake "${CMAKE_OPTS[@]}" ..
Guolin Ke's avatar
Guolin Ke committed
138
139
fi

140
make _lightgbm -j4 || exit -1
Guolin Ke's avatar
Guolin Ke committed
141

142
cd $BUILD_DIRECTORY/python-package && python setup.py install --precompile --user || exit -1
143
pytest $BUILD_DIRECTORY/tests || exit -1
Guolin Ke's avatar
Guolin Ke committed
144
145

if [[ $TASK == "regular" ]]; then
146
147
148
149
    if [[ $AZURE == "true" ]]; then
        if [[ $OS_NAME == "macos" ]]; then
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.dylib
        else
150
151
152
153
            if [[ $COMPILER == "gcc" ]]; then
                objdump -T $BUILD_DIRECTORY/lib_lightgbm.so > $BUILD_DIRECTORY/objdump.log || exit -1
                python $BUILD_DIRECTORY/helpers/check_dynamic_dependencies.py $BUILD_DIRECTORY/objdump.log || exit -1
            fi
154
155
            cp $BUILD_DIRECTORY/lib_lightgbm.so $BUILD_ARTIFACTSTAGINGDIRECTORY/lib_lightgbm.so
        fi
Guolin Ke's avatar
Guolin Ke committed
156
    fi
157
    cd $BUILD_DIRECTORY/examples/python-guide
Guolin Ke's avatar
Guolin Ke committed
158
159
160
161
    sed -i'.bak' '/import lightgbm as lgb/a\
import matplotlib\
matplotlib.use\(\"Agg\"\)\
' plot_example.py  # prevent interactive window mode
162
    sed -i'.bak' 's/graph.render(view=True)/graph.render(view=False)/' plot_example.py
Guolin Ke's avatar
Guolin Ke committed
163
    for f in *.py; do python $f || exit -1; done  # run all examples
164
    cd $BUILD_DIRECTORY/examples/python-guide/notebooks
Nikita Titov's avatar
Nikita Titov committed
165
    conda install -q -y -n $CONDA_ENV ipywidgets notebook
166
    jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb || exit -1  # run all notebooks
Guolin Ke's avatar
Guolin Ke committed
167
fi