Custom build backend for Python

1k Views Asked by At

I would like to write my own Python build backend that can used in pyproject.toml like

[build-system]
requires = ["setuptools>=42", "wheel", "mybackend"]
build-backend = "mybackend.build_meta"

and that does the same thing as setuptools, except that it preprends the line

# nice code!

to each .py file. What entry points would mybackend have to provide, and is it possible to somehow "inherit" from setuptools?

1

There are 1 best solutions below

0
On

One way to extend setuptools is to use wrap those in your own build_wheel/build_sdist like

from setuptools.build_meta import build_sdist as setuptools_build_sdist
from setuptools.build_meta import build_wheel as setuptools_build_wheel


def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
    return setuptools_build_wheel(
        wheel_directory,
        config_settings=config_settings,
        metadata_directory=metadata_directory,
    )


def build_sdist(sdist_directory, config_settings=None):
    return setuptools_build_sdist(sdist_directory, config_settings)

Instead of immediately returning the output of the setuptools functions (e.g., the tar-file), one can work on those files.