Pass config_settings to hatchling plugins
As a Python packager writing custom hatchling build hooks (using hatch_build.py), I would like hatchling to support passing config_settings to the hatchling build and metadata hooks so that users can customize certain aspects of the build experience (i.e., build jobs, compiler choice, etc.) using a consistent interface.
The PEP 517 specification includes a way to pass a config_settings dictionary, and hatchling includes config_settings in its PEP 517 hooks implementation, but it does nothing to make it available to the plugins, or any part of hatchling for that matter.
The current workaround is to use environment variables to pass configuration to the plugins. But that has the following problems:
- Environment variables may already be set in the shell and used without being explicitly set, inadvertently affecting builds
- The interface for setting environment variables is inconsistent across platforms and, therefore, requires multiple sets of instructions that may confuse users
- Passing multiple values is not trivially supported using environment variables
Passing config_settings to plugins solves these problems in the following ways:
- Settings must be explicitly set using the build frontend's interface (i.e.,
pyproject-build -C jobs=8) - The interface for config settings is consistent for each build frontend across different platforms
- Passing multiple values is directly supported by using the config key multiple times
Pip supports passing config settings from the install and wheel commands using the -C/--config-settings command-line option. And the build package provides support using the -C/--config-setting option.
This could be accomplished in a backward-compatible way by attaching the config_settings dictionary (or some wrapper around it) to the build and metadata hook implementation instances.
I generally speaking very much dislike config_settings however I take your feature request about build-time configurability seriously. I will think about how best to do this!