Trimatix / Carica

Python module that populates variables from TOML config documents, and generates config documents from python variables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Load docstrings -> toml

Trimatix opened this issue · comments

This feature is mostly complete but tests fail under certain conditions when saving preceeding comments for structural variables (tables and arrays).

Variable is not ordering is not guaranteed. This is due to the TOML spec requiring that structural variables appear at the end of a document to resolve ambiguities in the variable heirarchy.
Since ordering is not guaranteed, and tomlkit does not explicitly know that preceeding comments are associated with variables, structural variables can be moved around during document rendering, with their preceeding comments left behind in undesirable locations in the document.

An unideal solution to this problem could make use of reflection, in a sense. A tomlkit document maintains two private fields:

  • _body: A list of (key (name), value) tuples
  • _map: A dictionary mapping a key (name) to the index of the key in _body.
    It may be possible to manipulate the rendering order of the document by manually moving the index of preceeding comments to just before the new table location. Depending on when reordering takes place, this may or may not be feasible.

there may be other easier solutions, or if all else fails, we can just manipulate the rendered string.