Member-only story
Building Packages in Python
In the Python ecosystem, building and installing packages can be achieved using various tools, each of these tools is known as a “build backend” or a “build system”. These include setuptools
, flit
, poetry
, and others. Each of these backends might handle the build process (compiling code, moving files, etc.) in its own way.
pip
(pip Install Packages), the Python package installer, does not directly handle the build process. Instead, it delegates that responsibility to these build backends. This allows pip to focus on its core functionality, which is managing and resolving dependencies, downloading packages, and triggering their installation.
The interface pip uses to interact with these build backends is defined in PEP 517 and PEP 518. This interface defines how pip should invoke the build backend, and what the backend needs to do in response.
Here’s a very simple example:
Let’s say you have the following pyproject.toml
file:
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
The [build-system] block is required by PEP 518. It specifies the build requirements and the build backend. In this case, the build requirement is poetry-core>=1.0.0
, and the build…