From 885ea3ad454d27f268de794bf2518b8e8f628fd8 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 13 Feb 2023 21:14:06 -0600 Subject: [PATCH] [ci] [python-package] enforce 'twine check' and 'check-wheel-contents' on Python distributions (#5707) --- .ci/check_python_dists.sh | 20 ++++++++++++++++++++ .ci/test.sh | 9 +++++++++ .ci/test_windows.ps1 | 2 ++ python-package/setup.py | 1 + 4 files changed, 32 insertions(+) create mode 100644 .ci/check_python_dists.sh diff --git a/.ci/check_python_dists.sh b/.ci/check_python_dists.sh new file mode 100644 index 000000000..e7e4a86b4 --- /dev/null +++ b/.ci/check_python_dists.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +DIST_DIR=${1} + +echo "checking Python package distributions in '${DIST_DIR}'" + +pip install \ + -qq \ + check-wheel-contents \ + twine || exit -1 + +echo "twine check..." +twine check --strict ${DIST_DIR}/* || exit -1 + +if { test "${TASK}" = "bdist" || test "${METHOD}" = "wheel"; }; then + echo "check-wheel-contents..." + check-wheel-contents ${DIST_DIR}/*.whl || exit -1 +fi + +echo "done checking Python package distributions" diff --git a/.ci/test.sh b/.ci/test.sh index 672b69889..34949cfc2 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -154,6 +154,7 @@ fi if [[ $TASK == "sdist" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v || exit -1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz $BUILD_ARTIFACTSTAGINGDIRECTORY @@ -163,6 +164,7 @@ if [[ $TASK == "sdist" ]]; then elif [[ $TASK == "bdist" ]]; then if [[ $OS_NAME == "macos" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --plat-name=macosx --python-tag py3 || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 mv dist/lightgbm-$LGB_VER-py3-none-macosx.whl dist/lightgbm-$LGB_VER-py3-none-macosx_10_15_x86_64.macosx_11_6_x86_64.macosx_12_5_x86_64.whl if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp dist/lightgbm-$LGB_VER-py3-none-macosx*.whl $BUILD_ARTIFACTSTAGINGDIRECTORY @@ -175,6 +177,7 @@ elif [[ $TASK == "bdist" ]]; then PLATFORM="manylinux2014_$ARCH" fi cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --integrated-opencl --plat-name=$PLATFORM --python-tag py3 || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 if [[ $PRODUCES_ARTIFACTS == "true" ]]; then cp dist/lightgbm-$LGB_VER-py3-none-$PLATFORM.whl $BUILD_ARTIFACTSTAGINGDIRECTORY fi @@ -193,11 +196,13 @@ if [[ $TASK == "gpu" ]]; then grep -q 'std::string device_type = "gpu"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done if [[ $METHOD == "pip" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--gpu || exit -1 pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1 exit 0 elif [[ $METHOD == "wheel" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --gpu || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1 pytest $BUILD_DIRECTORY/tests || exit -1 exit 0 @@ -212,11 +217,13 @@ elif [[ $TASK == "cuda" ]]; then grep -q 'gpu_use_dp = true' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done if [[ $METHOD == "pip" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda || exit -1 pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1 exit 0 elif [[ $METHOD == "wheel" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1 pytest $BUILD_DIRECTORY/tests || exit -1 exit 0 @@ -226,11 +233,13 @@ elif [[ $TASK == "cuda" ]]; then elif [[ $TASK == "mpi" ]]; then if [[ $METHOD == "pip" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--mpi || exit -1 pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1 exit 0 elif [[ $METHOD == "wheel" ]]; then cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --mpi || exit -1 + sh $BUILD_DIRECTORY/.ci/check_python_dists.sh $BUILD_DIRECTORY/python-package/dist || exit -1 pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1 pytest $BUILD_DIRECTORY/tests || exit -1 exit 0 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 79b35faaf..4735de829 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -73,6 +73,7 @@ if ($env:TASK -eq "regular") { elseif ($env:TASK -eq "sdist") { cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py sdist --formats gztar ; Check-Output $? + sh $env:BUILD_SOURCESDIRECTORY/.ci/check_python_dists.sh $env:BUILD_SOURCESDIRECTORY/python-package/dist ; Check-Output $? cd dist; pip install @(Get-ChildItem *.gz) -v ; Check-Output $? } elseif ($env:TASK -eq "bdist") { @@ -88,6 +89,7 @@ elseif ($env:TASK -eq "bdist") { conda activate $env:CONDA_ENV cd $env:BUILD_SOURCESDIRECTORY/python-package python setup.py bdist_wheel --integrated-opencl --plat-name=win-amd64 --python-tag py3 ; Check-Output $? + sh $env:BUILD_SOURCESDIRECTORY/.ci/check_python_dists.sh $env:BUILD_SOURCESDIRECTORY/python-package/dist ; Check-Output $? cd dist; pip install --user @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { diff --git a/python-package/setup.py b/python-package/setup.py index 21d5b0336..b1620929f 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -348,6 +348,7 @@ if __name__ == "__main__": version=version, description='LightGBM Python Package', long_description=readme, + long_description_content_type='text/x-rst', python_requires='>=3.6', install_requires=[ 'wheel',