@@ -289,11 +289,11 @@ create_isolated_source_dir
289289
290290cd ./lightgbm-python
291291
292- # installation involves building the wheel + `pip install`-ing it
292+ # if 'install' was passed, choose the type of package to build and install
293293if test " ${INSTALL} " = true ; then
294294 if test " ${PRECOMPILE} " = true ; then
295- BUILD_SDIST=true
296- BUILD_WHEEL=false
295+ BUILD_SDIST=false
296+ BUILD_WHEEL=true
297297 BUILD_ARGS=" "
298298 rm -rf \
299299 ./cmake \
@@ -302,16 +302,22 @@ if test "${INSTALL}" = true; then
302302 ./include \
303303 ./src \
304304 ./swig
305- # use regular-old setuptools for these builds, to avoid
306- # trying to recompile the shared library
305+ # avoid trying to recompile, just use hatchling and copy in relevant files
307306 sed -i.bak -e ' /start:build-system/,/end:build-system/d' pyproject.toml
308- # shellcheck disable=SC2129
309- echo ' [build-system]' >> ./pyproject.toml
310- echo ' requires = ["setuptools"]' >> ./pyproject.toml
311- echo ' build-backend = "setuptools.build_meta"' >> ./pyproject.toml
312- echo " " >> ./pyproject.toml
313- echo " recursive-include lightgbm *.dll *.dylib *.so" > ./MANIFEST.in
314- echo " " >> ./MANIFEST.in
307+
308+ # replace build backend configuration
309+ cat >> ./pyproject.toml << EOF
310+
311+ [build-system]
312+ requires = ["hatchling>=1.27.0"]
313+ build-backend = "hatchling.build"
314+
315+ [tool.hatch.build.targets.wheel]
316+ # do not consider .gitignore when choosing files to include / exclude
317+ ignore-vcs = true
318+ packages = ["lightgbm"]
319+
320+ EOF
315321 mkdir -p ./lightgbm/lib
316322 if test -f ../lib_lightgbm.so; then
317323 echo " [INFO] found pre-compiled lib_lightgbm.so"
@@ -338,7 +344,11 @@ if test "${INSTALL}" = true; then
338344 exit 1
339345 fi
340346 rm -f ./* .bak
341- else
347+ fi
348+
349+ # at this point, if 'install' was passed but the package type wasn't indicated, prefer wheel
350+ if test " ${BUILD_SDIST} " = false && test " ${BUILD_WHEEL} " = false ; then
351+ echo " [INFO] 'install' passed but no package type ('bdist_wheel', 'sdist') chosen. Defaulting to 'bdist_wheel'."
342352 BUILD_SDIST=" false"
343353 BUILD_WHEEL=" true"
344354 fi
366376
367377if test " ${INSTALL} " = true ; then
368378 echo " [INFO] --- installing lightgbm ---"
369- cd ../dist
379+ cd ..
370380 if test " ${BUILD_WHEEL} " = true ; then
371- PACKAGE_NAME =" $( echo lightgbm* .whl) "
381+ PACKAGE_FILE =" $( echo dist/ lightgbm* .whl) "
372382 else
373- PACKAGE_NAME =" $( echo lightgbm* .tar.gz) "
383+ PACKAGE_FILE =" $( echo dist/ lightgbm* .tar.gz) "
374384 fi
375- # ref for use of '--find-links': https://stackoverflow.com/a/52481267/3986677
376385 # shellcheck disable=SC2086
377386 pip install \
378387 ${PIP_INSTALL_ARGS} \
379388 --force-reinstall \
380389 --no-cache-dir \
381390 --no-deps \
382- --find-links=. \
383- " ${PACKAGE_NAME} "
384- cd ../
391+ " ${PACKAGE_FILE} "
385392fi
386393
387394echo " [INFO] cleaning up"
0 commit comments