-
Notifications
You must be signed in to change notification settings - Fork 4k
[python-package] use PEP 639 license metadata, bump toscikit-build-core>=0.11.0, use hatchling instead of setuptools
#7135
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
Conversation
scikit-build-core>=0.11.0, use hatchling instead of setuptools
| BUILD_SDIST=true | ||
| BUILD_WHEEL=false | ||
| BUILD_SDIST=false | ||
| BUILD_WHEEL=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With hatchling we have tighter control over package contents, so --precompile can build a wheel 😁
| cd .. | ||
| if test "${BUILD_WHEEL}" = true; then | ||
| PACKAGE_NAME="$(echo lightgbm*.whl)" | ||
| PACKAGE_FILE="$(echo dist/lightgbm*.whl)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this echo is portable enough, then we can avoid using --find-links in pip.
Not strictly related to the rest of this change, but just something else I noticed that could help with building from source using build-python.sh.
|
|
||
| sudo apt-get -y install python-pip | ||
| sudo -H pip install setuptools numpy scipy scikit-learn -U | ||
| sudo -H pip install numpy scipy scikit-learn -U |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setuptools was only helpful here because it gets system installed by apt-get install python-pip on Ubuntu, and so needed to be upgraded.
Any other build-time requirements (like scikit-build-core) don't need to be separately installed by default, because they'll be set up in pip's isolated build environment.
|
|
||
| # at this point, if 'install' was passed but the package type wasn't indicated, prefer wheel | ||
| if test "${BUILD_SDIST}" = false && test "${BUILD_WHEEL}" = false; then | ||
| echo "[INFO] 'install' passed but no package type ('bdist_wheel', 'sdist') chosen. Defaulting to 'bdist_wheel'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test like this:
$ sh build-python.sh install
...
[INFO] 'install' passed but no package type ('bdist_wheel', 'sdist') chosen. Defaulting to 'bdist_wheel'.
[INFO] --- building wheel ---
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
- scikit-build-core>=0.11.0
* Getting build dependencies for wheel...
* Building wheel...
...
Successfully built lightgbm-4.6.0.99-py3-none-macosx_14_0_arm64.whl
[INFO] --- installing lightgbm ---
Processing ./dist/lightgbm-4.6.0.99-py3-none-macosx_14_0_arm64.whl
Installing collected packages: lightgbm
Attempting uninstall: lightgbm
Found existing installation: lightgbm 4.6.0.99
Uninstalling lightgbm-4.6.0.99:
Successfully uninstalled lightgbm-4.6.0.99
Successfully installed lightgbm-4.6.0.99|
|
||
| sudo apt-get -y install python-pip | ||
| sudo -H pip install setuptools numpy scipy scikit-learn -U | ||
| sudo apt-get -y install python3-pip python3-venv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python3-venv is required because now these commands build a wheel (not an sdist), with build isolation.
Found that in testing on Ubuntu 22.04: #6665 (comment)
| echo "" >> ./MANIFEST.in | ||
|
|
||
| # replace build backend configuration | ||
| cat >> ./pyproject.toml <<EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using heredocs for readability. See this old review thread: #6681 (comment)
scikit-build-core>=0.11.0, use hatchling instead of setuptoolsscikit-build-core>=0.11.0, use hatchling instead of setuptools
borchero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Big fan of hatchling ;)
|
Thanks @borchero . Yeah I've started trying it out recently and am really liking it! Inspired by pyOpenSci's write-up here: https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-build-tools.html#about-hatch |
Fixes #6665
Replaces #6681
This project uses
setuptoolswhen building a Python wheel with a pre-compiledlib_lightgbm.{dll,dylib,so}, like this:cmake -B build -S . cmake --build build --target _lightgbm sh build-python.sh install --precompileThat's helpful for users building with customizations (like the MPI version), and that pattern used in all the
TASK=regularCI jobs here.For a few months, that's been raising warnings about license metadata, warning that a new
setuptoolsin February 2026 may turn those warnings into errors.warning text (click me)
Warnings below from a recent
regularjob (build link)This resolves those warnings with following changes:
scikit-build-coreto the earliest version that supported PEP 639 (v0.11.0)setuptoolstohatchlingI found those specific floors while doing something similar for RAPIDS projects: rapidsai/build-planning#152
Benefits of these changes
setuptoolsthis yearconda-forge, which has similar warnings because thelightgbmfeedstock patches insetuptoolsas the build backed (conda-forge/lightgbm-feedstock code link)scikit-build-corelightgbminstallationsNotes for Reviewers
Why
scikit-build-core>=0.11.0?Tat's the first version that support PEP 639 license metadata.
I recently updated all of RAPIDS to that version (rapidsai/build-planning#152) and didn't encounter any problems, so I think it's safe.
why switch to
hatchling? how does that affect portability?hatchlingmakes--precompilebuilds oflightgbmmore portable and more backwards-compatible than the current setup withsetuptools😁hatchlingis a pure Python package (just a py3-none-any wheel), so it doesn't bring any new constraints on GLIBC version, CPU architecture, or operating system.It also avoids these
setuptools-specific problems:setuptoolsbeing system-installed on some linux distributions as a hard requirement ofpip(see [python-package] UNKNOWN python package #6665, especially [python-package] UNKNOWN python package #6665 (comment))setuptoolssometimes being declared as a runtime dependency oflightgbm's depenendenciespandaspackages on conda-forge have a runtime dependency onsetuptools<60For these
--precompilebuilds, we only need very very simple Python packaging: create a zip archive out of a directory and write the appropriate wheel metadata. No compiler flags, handling of symlinks, other configuration for sdists, etc.This is a long-term fix for #6665, replacing #6681 😁 (see #6665 (comment))
why
hatchling>=1.27.0specifically?hatchling==1.27.0was the final version to support Python 3.9 (pypa/hatch#2097), the oldest Pythonlightgbmsupports.