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

WIP: [ci] [python-package] support setuptools<61 in build-python.sh (fixes #6665) #6681

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 12 additions & 2 deletions build-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,18 @@ if test "${INSTALL}" = true; then
echo 'requires = ["setuptools"]' >> ./pyproject.toml
echo 'build-backend = "setuptools.build_meta"' >> ./pyproject.toml
echo "" >> ./pyproject.toml
echo "recursive-include lightgbm *.dll *.dylib *.so" > ./MANIFEST.in
echo "recursive-include lightgbm VERSION.txt py.typed *.py *.so" > ./MANIFEST.in
echo "" >> ./MANIFEST.in
# create a setup.cfg for systems with setuptools<61 (e.g Ubuntu 22.04 python3-pip)
# ref: https://github.com/microsoft/LightGBM/issues/6665#issuecomment-2412748042
echo '[metadata]' > ./setup.cfg
echo 'name = lightgbm' >> ./setup.cfg
echo "version = $(head -1 ../VERSION.txt)" >> ./setup.cfg
echo 'description = lightgbm (built with LightGBM/build-python.sh)' >> ./setup.cfg
echo "" >> ./setup.cfg
echo '[options]' >> ./setup.cfg
echo 'packages = lightgbm' >> ./setup.cfg
echo 'include_package_data = True' >> ./setup.cfg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about having a "template" file (say, template_setup.cfg) with these lines which will be renamed (or its' content will be inserted somewhere) when needed? TBH, these echos are really hard to read 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, I'm really unhappy with these.

I'd love to avoid checking any more files into source control for this purpose. What about using heredocs?

It would look a little weird in the script because we'd have to left-justify them (I think), but overall they'd be easier to read.

like this:

        # use regular-old setuptools for these builds, to avoid
        # trying to recompile the shared library
        sed -i.bak -e '/start:build-system/,/end:build-system/d' pyproject.toml
        echo '[build-system]' >> ./pyproject.toml
        echo 'requires = ["setuptools"]' >> ./pyproject.toml
        echo 'build-backend = "setuptools.build_meta"' >> ./pyproject.toml
        echo "" >> ./pyproject.toml
cat > ./MANIFEST.in <<EOF
recursive-include lightgbm \*.dll \*.dylib \*.so
EOF
cat > ./setup.cfg <<EOF
[options]
packages = lightgbm
include_package_data = True
EOF
        mkdir -p ./lightgbm/lib
        if test -f ../lib_lightgbm.so; then
            echo "found pre-compiled lib_lightgbm.so"
            cp ../lib_lightgbm.so ./lightgbm/lib/lib_lightgbm.so
        elif test -f ../lib_lightgbm.dylib; then
            echo "found pre-compiled lib_lightgbm.dylib"
            cp ../lib_lightgbm.dylib ./lightgbm/lib/lib_lightgbm.dylib
        elif test -f ../Release/lib_lightgbm.dll; then
            echo "found pre-compiled Release/lib_lightgbm.dll"
            cp ../Release/lib_lightgbm.dll ./lightgbm/lib/lib_lightgbm.dll
        elif test -f ../windows/x64/DLL/lib_lightgbm.dll; then
            echo "found pre-compiled windows/x64/DLL/lib_lightgbm.dll"
            cp ../windows/x64/DLL/lib_lightgbm.dll ./lightgbm/lib/lib_lightgbm.dll
            cp ../windows/x64/DLL/lib_lightgbm.lib ./lightgbm/lib/lib_lightgbm.lib
        fi
        rm -f ./*.bak

That'd be a short-term fix... longer-term, I think we could use CMake to get all this stuff out of this script, like having something of this form:

find_library(lightgbm)
if(lightgbm_FOUND)
   return()
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using heredocs?

Looks much better than echos 👍

mkdir -p ./lightgbm/lib
if test -f ../lib_lightgbm.so; then
echo "found pre-compiled lib_lightgbm.so"
Expand Down Expand Up @@ -376,4 +386,4 @@ if test "${INSTALL}" = true; then
fi

echo "cleaning up"
rm -rf ./lightgbm-python
#rm -rf ./lightgbm-python
Loading