`poetry add`, but for PEP 621?

This is an innocent sentence with a large amount of complexity behind it. That is because TOML is supposed to be human-centered (“A config file format for humans”), and so you absolutely have to be able to maintain things like comments in the toml file correctly.

This is not a trivial thing to do, because when you just .load() the toml file and then .dump() it again with an additional dependency, you’ve lost all those comments, plus other things that people have opinions™ about (order of sections, inlining of tables, etc.).

It’s a much larger space than just reading a toml, and the main reason why the 3.11 stdlib-implementation comes without writing capabilities (see e.g. this thread). This info might be out of date, but a year ago, only tomlkit supported style-preservation (and perhaps unsurprisingly, this is what poetry uses; indeed it’s written by the same people).

Adopting something like this IMO requires either:

  • having tomlkit as a dependency everywhere (yet more bootstrapping problems)
  • getting a style-preserving TOML parser/writer into the stdlib
3 Likes