Pass config_settings from build frontend to builders#2240
Pass config_settings from build frontend to builders#2240brandon-avantus wants to merge 2 commits into
Conversation
`uv build`, `pip wheel`, and `pyproject-build` (from the build package) all support passing config settings, as defined in PEP 517, to the build backend. Until now, `hatchling.build` ignored them. This change passes the `config_settings` dictionary on to `SdistBuilder` and `WheelBuilder` so that custom build scripts can access those settings when passed by frontends that support it. See pypa#1072
|
I just realized this is incomplete. I need to get the |
Ensure `config_settings` get passed from builders to hook implementations.
|
Passing |
I do not think the reluctance is fully this. I wont speak for Ofek but in general hatchling is meant to serve as a build backend that handles things out of the box for you. And this line from the config_settings section of the PEP somewhat go against our philosophy with hatchling and hatch:
I would point to https://hatch.pypa.io/latest/why/#build-backend which talks about the why of hatchling and what it is trying to do that other build backends might not offer. |
|
@cjames23 just copying my comment from #1072
I understand that "hatchling is meant to serve as a build backend that handles things out of the box for you". This is a good ideal, but I don't really understand how hatchling will be able to anticipate my needs for a hatchling plugin that wraps a build system like cmake or meson. A build system plugin needs the config_settings escape hatch for configuring things like debug/release builds. As the zen of python says...
Of course, https://hatch.pypa.io/latest/why/#build-backend seems to imply that it doesn't want to support any kind of building extension modules:
I quite like the hatchling plugin system, its useful for composing different types of functionality together to build a python wheel, and allows me to more easily do things that are more annoying to do in the build system. For now, I'm continuing to use the hacky workaround I posted in my hatch plugin that wraps meson. It works fine for me, but I'd rather official support exist instead. |
As a Python packager writing custom hatchling build hooks (using hatch_build.py), I would like hatchling to support passing
config_settingsfrom build frontends that support it to hatchling builders so that users can customize certain aspects of the build experience (i.e., build jobs, compiler choice, etc.) using the command-line options provided by build frontends.PEP 517 defines a
config_settingsdictionary in the backend hooks specifications for passing configuration from build frontends. Many build frontends already support passing inconfig_settingsusing the -C/--config-settings command-line option.Currently, hatchling does not pass
config_settingson to builders. I finally realized that the reluctance to implement such a feature in hatch, as indicated by responses in #1072, stem from the ambiguity in how frontends should implement the feature. What I'm suggesting here is not that we add support to the hatch frontend, but that we provide the backend with settings from frontends that already support it.See #1072
Please let me know if anything should be added to the documentation or if additional tests would be helpful.