Conversation
* Generate the RST from TOML file through a Python script (`toml_parser.py`). It can be executed as a standalone script or integrated into Sphinx. * Enhance `conf.py` to read the TOML config(s) and create the generated file. The generate file is included in `reference/env-toml/index.rst`. * The generated file has a different extension than .rst (actually `.rst.inc`). This was necessary otherwise you get a warning from Sphinx about duplicate labels. * Enrich the TOML file with comments similar to "docstrings": it contains the syntax "KEYNAME(TYPE): DESCRIPTION" This is a kind of "self-documenting" approach. * Currently, the standard tomllib library doesn't preserve comments. To not rely on a different library, we need to read it line by line. :( * There is a small optimization in the conf.py file: the .rst.inc file is only generated when the TOML file has a newer date.
0069a90 to
b34df39
Compare
Coverage ReportFor commit 14c8028 Click to expand Coverage Report Name Stmts Miss Branch BrPart Cover
--------------------------------------------------------------------------------
+ src/docbuild/cli/cmd_check/process.py 60 0 22 1 98.8%
+ src/docbuild/utils/pidlock.py 79 1 14 1 97.8%
+ src/docbuild/cli/cmd_validate/process.py 178 3 52 2 97.8%
+ src/docbuild/config/xml/stitch.py 48 1 12 1 96.7%
+ src/docbuild/cli/callback.py 35 0 10 2 95.6%
+ src/docbuild/cli/cmd_metadata/metaprocess.py 167 10 42 7 91.9%
- src/docbuild/cli/cmd_config/__init__.py 9 1 0 0 88.9%
- src/docbuild/cli/cmd_cli.py 86 11 6 3 84.8%
- src/docbuild/cli/cmd_check/__init__.py 18 5 2 0 65.0%
- src/docbuild/cli/cmd_build/__init__.py 13 5 0 0 61.5%
- src/docbuild/cli/cmd_metadata/__init__.py 27 10 2 0 58.6%
- src/docbuild/cli/cmd_config/environment.py 11 6 2 0 38.5%
--------------------------------------------------------------------------------
+ TOTAL 2744 53 638 17 97.8%
47 files skipped due to complete coverage. |
| # port(int): Port number to listen on. Uncomment and set to enable. | ||
| port = 80 |
There was a problem hiding this comment.
The port key in the [server] section is now active (uncommented) with a default of 80. If we want the example to stay 'safe' by default, we might want to keep it commented out, though the parser should still be able to show it as an option if configured to do so. WDYT?
There was a problem hiding this comment.
You make an excellent observation! 👍
I'm not sure yet how to deal with such values that are disabled in the TOML, but should be displayed in the doc. Any idea?
There was a problem hiding this comment.
That’s the classic 'Reference vs. Example' dilemma. Since we want to keep the TOML safe but the docs informative, here are two suggestions that can be done:
- Keep the line active but set it to a 'disabled' state, like
port = 0. You can then update the comment to:# port(int): Port number. Set to 80 for default or 0 to disable.This keeps the parser logic simple and the key visible to users. - We could tweak
toml_parser.pyto look for an explicit default in the comment, for example:# port(int): Port number. Default: 80. If the parser finds this, it uses it for the RST regardless of whether the TOML line is commented out.
Personally, I like the option 1. It is quite common in TOML examples and ensures the user does not have to guess where to add the key later. What do you think?
Hi @tomschr thanks a lot for the awesome work. The "Documentation as Code" approach is excellent. Syncing the documentation directly with
Great engineering to keep the build dependency-free. Approved. |

toml_parser.py). It can be executed as a standalone script or is integrated into Sphinx.conf.pyto read the TOML config(s) and create the generated file. The generated file is included inreference/env-toml/index.rst..rst(actually.rst.inc). This was necessary otherwise you get a warning from Sphinx about "duplicate labels".KEYNAME(TYPE): DESCRIPTIONas a "self-documenting" approach.conf.pyfile: the.rst.incfile is only generated when the TOML file has a newer date.Additional changes that were needed:
github-actiongroup inpyproject.toml. This requirestestsanddocsasconf.pyrequires Sphinx now.workflows/ci.ymlto use the newgithub-actiongroup.uv.lockfile to contain this new group too.Screenshot
Meaning of the callouts in the image:
reference/env-toml/index.rstreference/env-toml/index.rstetc/docbuild/env.example.tomletc/docbuild/env.example.tomletc/docbuild/env.example.toml