Fix config-settings handling in pip install (#9115)
* Fix config_settings handling in pip install * Fix formatting * Fix flag use_system_libxgboost * Add setuptools to doc requirements.txt * Fix mypy
This commit is contained in:
parent
09b44915e7
commit
0cd4382d72
2
.github/workflows/python_tests.yml
vendored
2
.github/workflows/python_tests.yml
vendored
@ -66,7 +66,7 @@ jobs:
|
|||||||
cd python-package
|
cd python-package
|
||||||
python --version
|
python --version
|
||||||
python -m build --sdist
|
python -m build --sdist
|
||||||
pip install -v ./dist/xgboost-*.tar.gz
|
pip install -v ./dist/xgboost-*.tar.gz --config-settings use_openmp=False
|
||||||
cd ..
|
cd ..
|
||||||
python -c 'import xgboost'
|
python -c 'import xgboost'
|
||||||
|
|
||||||
|
|||||||
@ -11,4 +11,5 @@ myst-parser
|
|||||||
xgboost_ray
|
xgboost_ray
|
||||||
sphinx-gallery
|
sphinx-gallery
|
||||||
pyspark
|
pyspark
|
||||||
cloudpickle
|
cloudpickle
|
||||||
|
setuptools
|
||||||
|
|||||||
@ -26,23 +26,18 @@ class BuildConfiguration: # pylint: disable=R0902
|
|||||||
# Special option: See explanation below
|
# Special option: See explanation below
|
||||||
use_system_libxgboost: bool = False
|
use_system_libxgboost: bool = False
|
||||||
|
|
||||||
def _set_config_setting(
|
def _set_config_setting(self, config_settings: Dict[str, Any]) -> None:
|
||||||
self, config_settings: Dict[str, Any], field_name: str
|
for field_name in config_settings:
|
||||||
) -> None:
|
|
||||||
if field_name in config_settings:
|
|
||||||
setattr(
|
setattr(
|
||||||
self,
|
self,
|
||||||
field_name,
|
field_name,
|
||||||
(config_settings[field_name].lower() in ["true", "1", "on"]),
|
(config_settings[field_name].lower() in ["true", "1", "on"]),
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise ValueError(f"Field {field_name} is not a valid config_settings")
|
|
||||||
|
|
||||||
def update(self, config_settings: Optional[Dict[str, Any]]) -> None:
|
def update(self, config_settings: Optional[Dict[str, Any]]) -> None:
|
||||||
"""Parse config_settings from Pip (or other PEP 517 frontend)"""
|
"""Parse config_settings from Pip (or other PEP 517 frontend)"""
|
||||||
if config_settings is not None:
|
if config_settings is not None:
|
||||||
for field_name in [x.name for x in dataclasses.fields(self)]:
|
self._set_config_setting(config_settings)
|
||||||
self._set_config_setting(config_settings, field_name)
|
|
||||||
|
|
||||||
def get_cmake_args(self) -> List[str]:
|
def get_cmake_args(self) -> List[str]:
|
||||||
"""Convert build configuration to CMake args"""
|
"""Convert build configuration to CMake args"""
|
||||||
|
|||||||
@ -130,20 +130,21 @@ def locate_or_build_libxgboost(
|
|||||||
"""Locate libxgboost; if not exist, build it"""
|
"""Locate libxgboost; if not exist, build it"""
|
||||||
logger = logging.getLogger("xgboost.packager.locate_or_build_libxgboost")
|
logger = logging.getLogger("xgboost.packager.locate_or_build_libxgboost")
|
||||||
|
|
||||||
libxgboost = locate_local_libxgboost(toplevel_dir, logger=logger)
|
|
||||||
if libxgboost is not None:
|
|
||||||
return libxgboost
|
|
||||||
if build_config.use_system_libxgboost:
|
if build_config.use_system_libxgboost:
|
||||||
# Find libxgboost from system prefix
|
# Find libxgboost from system prefix
|
||||||
sys_prefix = pathlib.Path(sys.prefix).absolute().resolve()
|
sys_prefix = pathlib.Path(sys.prefix).absolute().resolve()
|
||||||
libxgboost = sys_prefix / "lib" / _lib_name()
|
libxgboost_sys = sys_prefix / "lib" / _lib_name()
|
||||||
if not libxgboost.exists():
|
if not libxgboost_sys.exists():
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"use_system_libxgboost was specified but {_lib_name()} is "
|
f"use_system_libxgboost was specified but {_lib_name()} is "
|
||||||
f"not found in {libxgboost.parent}"
|
f"not found in {libxgboost_sys.parent}"
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("Using system XGBoost: %s", str(libxgboost))
|
logger.info("Using system XGBoost: %s", str(libxgboost_sys))
|
||||||
|
return libxgboost_sys
|
||||||
|
|
||||||
|
libxgboost = locate_local_libxgboost(toplevel_dir, logger=logger)
|
||||||
|
if libxgboost is not None:
|
||||||
return libxgboost
|
return libxgboost
|
||||||
|
|
||||||
if toplevel_dir.joinpath("cpp_src").exists():
|
if toplevel_dir.joinpath("cpp_src").exists():
|
||||||
|
|||||||
@ -79,7 +79,8 @@ def build_wheel(
|
|||||||
libxgboost = locate_or_build_libxgboost(
|
libxgboost = locate_or_build_libxgboost(
|
||||||
TOPLEVEL_DIR, build_dir=build_dir, build_config=build_config
|
TOPLEVEL_DIR, build_dir=build_dir, build_config=build_config
|
||||||
)
|
)
|
||||||
copy_with_logging(libxgboost, lib_path, logger=logger)
|
if not build_config.use_system_libxgboost:
|
||||||
|
copy_with_logging(libxgboost, lib_path, logger=logger)
|
||||||
|
|
||||||
with cd(workspace):
|
with cd(workspace):
|
||||||
wheel_name = hatchling.build.build_wheel(
|
wheel_name = hatchling.build.build_wheel(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user