Sphinx autodoc extension for documenting YAML files from comments
Project description
sphinxcontrib-autoyaml
This Sphinx autodoc extension documents YAML files from comments. Documentation is returned as reST definitions, e.g.:
This document:
###
# Enable Nginx web server.
enable_nginx: true
###
# Enable Varnish caching proxy.
enable_varnish: true
would be turned into text:
enable_nginx
Enable Nginx web server.
enable_varnish
Enable Varnish caching proxy.
See tests/examples/output/*.yml
and tests/examples/output/*.txt
for
more examples.
autoyaml
will take into account only comments which first line starts with
autoyaml_doc_delimiter
.
Usage
You can use autoyaml
directive, where you want to extract comments
from YAML file, e.g.:
Some title
==========
Documenting single YAML file.
.. autoyaml:: some_yml_file.yml
Options
Options available to use in your configuration:
- autoyaml_root(
..
) Look for YAML files relatively to this directory. - autoyaml_doc_delimiter(
###
) Character(s) which start a documentation comment. - autoyaml_comment(
#
) Comment start character(s). - autoyaml_level(
1
) Parse comments from nested structures n-levels deep.
Installing
Issue command:
pip install sphinxcontrib-autoyaml
And add extension in your project's conf.py
:
extensions = ["sphinxcontrib.autoyaml"]
Caveats
Mapping keys nested in sequences
Sequences are traversed as well, but they are not represented in output documentation. This extension focuses only on documenting mapping keys. It means that structure like this:
key:
###
# comment1
- - inner_key1: value
###
# comment2
inner_key2: value
###
# comment3
- inner_key3: value
will be flattened, so it will appear as though inner keys exist directly under
key
. Duplicated key documentation will be duplicated in output as well. See
tests/examples/output/comment-in-nested-sequence.txt
and
tests/examples/output/comment-in-nested-sequence.yml
to get a better
understanding how sequences are processed.
Complex mapping keys
YAML allows for complex mapping keys like so:
[1, 2]: value
These kind of keys won't be documented in output, because it's unclear how they should be represented as a string.
Flow-style entries
YAML allows writing complex data structures in single line like JSON. Documentation is generated only for the first key in such entry, so this:
###
# comment
key: {key1: value, key2: value, key3: value}
would yield documentation only for key
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sphinxcontrib-autoyaml-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a0f6550395f5a6e121cd7d76beeb899dbe45708bbcc3115eedd6b2cca7dc7ab |
|
MD5 | 4667747fc32438a775e11b0c571a2359 |
|
BLAKE2b-256 | 97012618ae404da948bf405ee59c1e80795097f88eb66b95d7742fd1340db437 |
Hashes for sphinxcontrib_autoyaml-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354e663e53e9a1bf621c9c07e26db964b34c86585e55e7a992a750d841eb67a9 |
|
MD5 | 357316c53fadcf5df7b892f566725d69 |
|
BLAKE2b-256 | 41a5b78070126683dfbc4938d670bd035bd75f42e79279ad5cf6e5526f2f4b46 |