Replace setup.py with pyproject.toml (#9021)
* Create pyproject.toml * Implement a custom build backend (see below) in packager directory. Build logic from setup.py has been refactored and migrated into the new backend. * Tested: pip wheel . (build wheel), python -m build --sdist . (source distribution)
This commit is contained in:
committed by
GitHub
parent
a7b3dd3176
commit
a5cd2412de
@@ -35,8 +35,9 @@ calls ``cibuildwheel`` to build the wheel. The ``cibuildwheel`` is a library tha
|
||||
suitable Python environment for each OS and processor target. Since we don't have Apple Silion
|
||||
machine in GitHub Actions, cross-compilation is needed; ``cibuildwheel`` takes care of the complex
|
||||
task of cross-compiling a Python wheel. (Note that ``cibuildwheel`` will call
|
||||
``setup.py bdist_wheel``. Since XGBoost has a native library component, ``setup.py`` contains
|
||||
a glue code to call CMake and a C++ compiler to build the native library on the fly.)
|
||||
``pip wheel``. Since XGBoost has a native library component, we created a customized build
|
||||
backend that hooks into ``pip``. The customized backend contains the glue code to compile the native
|
||||
library on the fly.)
|
||||
|
||||
*********************************************************
|
||||
Reproduce CI testing environments using Docker containers
|
||||
|
||||
@@ -23,6 +23,7 @@ Here are guidelines for contributing to various aspect of the XGBoost project:
|
||||
Community Guideline <community>
|
||||
donate
|
||||
coding_guide
|
||||
python_packaging
|
||||
unit_tests
|
||||
Docs and Examples <docs>
|
||||
git_guide
|
||||
|
||||
83
doc/contrib/python_packaging.rst
Normal file
83
doc/contrib/python_packaging.rst
Normal file
@@ -0,0 +1,83 @@
|
||||
###########################################
|
||||
Notes on packaging XGBoost's Python package
|
||||
###########################################
|
||||
|
||||
|
||||
.. contents:: Contents
|
||||
:local:
|
||||
|
||||
.. _packaging_python_xgboost:
|
||||
|
||||
***************************************************
|
||||
How to build binary wheels and source distributions
|
||||
***************************************************
|
||||
|
||||
Wheels and source distributions (sdist for short) are the two main
|
||||
mechanisms for packaging and distributing Python packages.
|
||||
|
||||
* A **source distribution** (sdist) is a tarball (``.tar.gz`` extension) that
|
||||
contains the source code.
|
||||
* A **wheel** is a ZIP-compressed archive (with ``.whl`` extension)
|
||||
representing a *built* distribution. Unlike an sdist, a wheel can contain
|
||||
compiled components. The compiled components are compiled prior to distribution,
|
||||
making it more convenient for end-users to install a wheel. Wheels containing
|
||||
compiled components are referred to as **binary wheels**.
|
||||
|
||||
See `Python Packaging User Guide <https://packaging.python.org/en/latest/>`_
|
||||
to learn more about how Python packages in general are packaged and
|
||||
distributed.
|
||||
|
||||
For the remainder of this document, we will focus on packaging and
|
||||
distributing XGBoost.
|
||||
|
||||
Building sdists
|
||||
===============
|
||||
|
||||
In the case of XGBoost, an sdist contains both the Python code as well as
|
||||
the C++ code, so that the core part of XGBoost can be compiled into the
|
||||
shared libary ``libxgboost.so`` [#shared_lib_name]_.
|
||||
|
||||
You can obtain an sdist as follows:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python -m build --sdist .
|
||||
|
||||
(You'll need to install the ``build`` package first:
|
||||
``pip install build`` or ``conda install python-build``.)
|
||||
|
||||
Running ``pip install`` with an sdist will launch CMake and a C++ compiler
|
||||
to compile the bundled C++ code into ``libxgboost.so``:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install -v xgboost-2.0.0.tar.gz # Add -v to show build progress
|
||||
|
||||
Building binary wheels
|
||||
======================
|
||||
|
||||
You can also build a wheel as follows:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip wheel --no-deps -v .
|
||||
|
||||
Notably, the resulting wheel contains a copy of the shared library
|
||||
``libxgboost.so`` [#shared_lib_name]_. The wheel is a **binary wheel**,
|
||||
since it contains a compiled binary.
|
||||
|
||||
|
||||
Running ``pip install`` with the binary wheel will extract the content of
|
||||
the wheel into the current Python environment. Since the wheel already
|
||||
contains a pre-built copy of ``libxgboost.so``, it does not have to be
|
||||
built at the time of install. So ``pip install`` with the binary wheel
|
||||
completes quickly:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install xgboost-2.0.0-py3-none-linux_x86_64.whl # Completes quickly
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
.. [#shared_lib_name] The name of the shared library file will differ
|
||||
depending on the operating system in use. See :ref:`build_shared_lib`.
|
||||
Reference in New Issue
Block a user