flo-schu / pymob

Python model building platform
MIT License
0 stars 0 forks source link

Write descriptions into config file at export, in order to create self documented configuration files #65

Open flo-schu opened 3 weeks ago

flo-schu commented 3 weeks ago

Pydantic fields have the possibility to specify descriptions https://docs.pydantic.dev/latest/concepts/fields/#customizing-json-schema

However, this is not accessed in the self.model_dump method of a pydantic Model. self.model_json_schema() exports descriptions, but they are in a JSON schema, which can not be immediately parsed to the config file.

From the JSON schema, sections and options can be extracted and a custom dictionary created.

To insert comments into cfg files with configparser, see https://stackoverflow.com/a/19432072