build icon indicating copy to clipboard operation
build copied to clipboard

Feature proposal: --config-json

Open henryiii opened this issue 7 months ago • 7 comments

I'd like to propose adding a feature from gpep517: --config-json. This is a replacement for --config-setting/-C that allows specification of the configure settings as a JSON object in a string. This is more flexible than the -C version, both allowing advanced use cases that are allowed by the PEP but not by most tools, as well as being ideal for piping through from tools. PEP 517 allows any dict here, but pip/build/uv have not taken advantage of that (expect for build's API, which does). cibuildwheel could likely use this, mapping its TOML config settings into this option. It also would be useful for testing, as currently backends like scikit-build-core either have to use the Python API or a gpep517 to test things that are beyond a simple string mapping. (I know about this tool because someone noticed that bools weren't working in config-settings, so I asked how they managed that and they said they were using gpep517).

Design:

  • I think using JSON is a simple, cross-language string format. Another option would be Python via literal_eval, but I think JSON is more universal across languages.
  • I'm fine with the name --config-json from gpep517, but I don't really have opinions here, happy with whatever.
  • I think taking a string is simpler than taking a filename, especially for scripting (which I assume is the main use case).
  • What happens when you specify both needs to be specified. It could be an error, or we could merge, with one overriding the other. Not sure which should override which; I'd be fine with an error if both specified TBH.

I'd like some feedback from pip/uv maintainers, since if we add this here, it is conceivable that other frontends might eventually be expected to add it too, especially if backends start expecting nested structures or bool/ints. As well as pip is also a frontend choice for cibuildwheel, and I'm adding native uv soon too.

Example using cibuildwheel:

[tool.cibuildwheel.config-settings]
build.targets = ["ext1", "ext2"]

could transform to

python -m build --config-json '{"build": {"targets": ["ext1", "ext2"}}'

While today it has to be:

[tool.cibuildwheel.config-settings]
"build.targets" = ["ext1", "ext2"]

which is expanded as

python -m build --config-setting=build.targets=ext1 --config-setting=build.targets=ext2

(scikit-build-core has to expand dots manually to mimic the full nested structure of the TOML config, as anything you can pass in TOML you can pass as --config-setting except top-level arrays)

henryiii avatar May 22 '25 03:05 henryiii

I'm happy to have this 👍

gaborbernat avatar May 27 '25 14:05 gaborbernat

I know that TOML tends to describe data at rest, but is there a good reason to prefer JSON to TOML here? python -m build --config-toml 'build.targets = ["ext1", "ext2"]' is easier both to read and write.

layday avatar May 27 '25 15:05 layday

Generally these get passed into Python code, so the user might have the Python code. JSON maps are closer to Python syntax than TOML one 🤔

gaborbernat avatar May 27 '25 15:05 gaborbernat

Could you try to extend your example to two items, please? ;)

Generally, json is much more commonly used as an interchange format. There are far more utilities to generate JSON then there are TOML, and JSON packs nicely into a single line, while TOML was intended as a user-writeable format, not an inline or autogenerated one.

Generating TOML in Python isn't supported even on 3.11+, so I think that immediately rules it out. ;)

henryiii avatar May 27 '25 15:05 henryiii

Could you try to extend your example to two items, please? ;)

Well, multiline shell strings are hardly revolutionary. Fish will even auto-indent new lines for you.

I didn't consider the scenario where you might want to generate the configuration in code, although I doubt it would ever rise to the level of complexity where you can't just construct TOML as a string.

layday avatar May 27 '25 16:05 layday

My vote is on JSON (over TOML) 👍

gaborbernat avatar May 27 '25 16:05 gaborbernat

We don't need to vote - I was just curious about the pros and cons.

layday avatar May 27 '25 16:05 layday