Skip to content

Commit

Permalink
Merge branch 'master' into ci/mypy-literals
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed May 9, 2023
2 parents e62f8d8 + 1c873af commit 7922149
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
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
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
CONDA_ENV: test-env
GITHUB_ACTIONS: 'true'
OS_NAME: 'linux'
PYTHON_VERSION: '3.10'
PYTHON_VERSION: '3.11'

jobs:
test:
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

0 comments on commit 7922149

Please sign in to comment.