Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] [python-package] move tool configuration to pyproject.toml #5872

Merged
merged 8 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions .ci/lint-python.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
#!/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}" \
--config=./python-package/setup.cfg \
. \
|| 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}" \
--config=./python-package/pyproject.toml \
. \
|| exit -1
echo "done running pydocstyle"

echo "running isort"
isort \
--check-only \
"${DIR_TO_CHECK}" \
--settings-path=./python-package/pyproject.toml \
. \
|| 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" \
--config-file=./python-package/pyproject.toml \
./python-package \
|| true
echo "done running mypy"
2 changes: 1 addition & 1 deletion .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if [[ $TASK == "lint" ]]; then
"r-lintr>=3.0"
source activate $CONDA_ENV
echo "Linting Python code"
sh ${BUILD_DIRECTORY}/.ci/lint-python.sh ${BUILD_DIRECTORY} || exit -1
sh ${BUILD_DIRECTORY}/.ci/lint-python.sh || exit -1
echo "Linting R code"
Rscript ${BUILD_DIRECTORY}/.ci/lint_r_code.R ${BUILD_DIRECTORY} || exit -1
echo "Linting C++ code"
Expand Down
5 changes: 5 additions & 0 deletions build-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ create_isolated_source_dir() {

cp -R ./python-package ./lightgbm-python

# temporarily remove these files until
# https://github.com/microsoft/LightGBM/issues/5061 is done
rm ./lightgbm-python/pyproject.toml
rm ./lightgbm-python/setup.cfg

cp LICENSE ./lightgbm-python/
cp VERSION.txt ./lightgbm-python/lightgbm/VERSION.txt

Expand Down
2 changes: 1 addition & 1 deletion python-package/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ To check that a contribution to the package matches its style expectations, run

.. code:: sh

sh .ci/lint-python.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
Expand Down
18 changes: 18 additions & 0 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.isort]
line_length = 120
skip_glob = [
"external_libs/*",
"lightgbm-python/*"
]

[tool.mypy]
exclude = 'build/*|compile/*|docs/*|examples/*|external_libs/*|lightgbm-python/*|tests/*'
ignore_missing_imports = true

[tool.pydocstyle]
add_ignore = [
'D105'
]
convention = 'numpy'
match = '(?!^test_|setup).*\.py'
match_dir = '^(?!^external_libs|lightgbm-python|test|example).*'
12 changes: 12 additions & 0 deletions python-package/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
ignore =
# line too long
E501,
# line break occurred before a binary operator
W503
exclude =
./.nuget,
./external_libs,
./lightgbm-python,
./python-package/build,
./python-package/compile