Unverified Commit 1f1ed5b4 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[ci] moving linting into small scripts (fixes #5142) (#5809)

parent da5160cf
#!/bin/sh
echo "running cpplint"
cpplint \
--filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length \
--recursive ./src ./include ./R-package ./swig ./tests \
|| exit -1
echo "done running cpplint"
echo "running cmakelint"
cmake_files=$(
find . -name CMakeLists.txt -o -path "./cmake/*.cmake" \
| grep -v external_libs
)
cmakelint \
--linelength=120 \
--filter=-convention/filename,-package/stdargs,-readability/wonkycase \
${cmake_files} \
|| exit -1
echo "done running cmakelint"
#!/bin/sh
DIR_TO_CHECK=${1}
echo "running flake8"
flake8 \
--ignore=E501,W503 \
--exclude=./.nuget,./external_libs,./python-package/build,./python-package/compile \
"${DIR_TO_CHECK}" \
|| exit -1
echo "done running flake8"
echo "running pydocstyle"
pydocstyle \
--convention=numpy \
--add-ignore=D105 \
--match-dir="^(?!^external_libs|test|example).*" \
--match="(?!^test_|setup).*\.py" \
"${DIR_TO_CHECK}" \
|| exit -1
echo "done running pydocstyle"
echo "running isort"
isort \
--check-only \
"${DIR_TO_CHECK}" \
|| exit -1
echo "done running isort"
echo "running mypy"
mypy \
--ignore-missing-imports \
--exclude 'build/' \
--exclude 'compile/' \
--exclude 'docs/' \
--exclude 'examples/' \
--exclude 'external_libs/' \
--exclude 'tests/' \
"${DIR_TO_CHECK}/python-package" \
|| true
echo "done running mypy"
......@@ -66,6 +66,7 @@ if [[ $TASK == "swig" ]]; then
fi
if [[ $TASK == "lint" ]]; then
cd ${BUILD_DIRECTORY}
conda create -q -y -n $CONDA_ENV \
${CONDA_PYTHON_REQUIREMENT} \
cmakelint \
......@@ -77,19 +78,11 @@ if [[ $TASK == "lint" ]]; then
"r-lintr>=3.0"
source activate $CONDA_ENV
echo "Linting Python code"
flake8 \
--ignore=E501,W503 \
--exclude=./.nuget,./external_libs,./python-package/build \
. || exit -1
pydocstyle --convention=numpy --add-ignore=D105 --match-dir="^(?!^external_libs|test|example).*" --match="(?!^test_|setup).*\.py" . || exit -1
isort . --check-only || exit -1
mypy --ignore-missing-imports python-package/ || true
sh ${BUILD_DIRECTORY}/.ci/lint-python.sh ${BUILD_DIRECTORY} || exit -1
echo "Linting R code"
Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit -1
echo "Linting C++ code"
cpplint --filter=-build/c++11,-build/include_subdir,-build/header_guard,-whitespace/line_length --recursive ./src ./include ./R-package ./swig ./tests || exit -1
cmake_files=$(find . -name CMakeLists.txt -o -path "*/cmake/*.cmake")
cmakelint --linelength=120 --filter=-convention/filename,-package/stdargs,-readability/wonkycase ${cmake_files} || exit -1
sh ${BUILD_DIRECTORY}/.ci/lint-cpp.sh || exit -1
exit 0
fi
......
......@@ -252,9 +252,15 @@ Refer to the walk through examples in `Python guide folder <https://github.com/m
Development Guide
-----------------
The code style of Python-package follows `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_. If you would like to make a contribution and not familiar with PEP 8, please check the PEP 8 style guide first. Otherwise, the check won't pass. Only E501 (line too long) and W503 (line break occurred before a binary operator) can be ignored.
The code style of Python-package follows `PEP 8 <https://www.python.org/dev/peps/pep-0008/>`_.
Documentation strings (docstrings) are written in the NumPy style.
The package's documentation strings (docstrings) are written in the `numpydoc style <https://numpydoc.readthedocs.io/en/latest/format.html>`_.
To check that a contribution to the package matches its style expectations, run the following from the root of the repo.
.. code:: sh
sh .ci/lint-python.sh .
.. |License| image:: https://img.shields.io/github/license/microsoft/lightgbm.svg
:target: https://github.com/microsoft/LightGBM/blob/master/LICENSE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment