Skip to main content

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

# Look for YAML files relatively to this directory.
autoyaml_root = ".."
# Character(s) which start a documentation comment.
autoyaml_doc_delimiter = "###"
# Comment start character(s).
autoyaml_comment = "#"
# Parse comments from nested structures n-levels deep.
autoyaml_level = 1
# Whether to use YAML SafeLoader
autoyaml_safe_loader = False

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib_autoyaml-1.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

sphinxcontrib_autoyaml-1.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file sphinxcontrib_autoyaml-1.1.2.tar.gz.

File metadata

  • Download URL: sphinxcontrib_autoyaml-1.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.1.0-27-amd64

File hashes

Hashes for sphinxcontrib_autoyaml-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6a56f93878735170e5504ca3030250960adafaffa7fb0d7177223d597874e9e9
MD5 09526a8634ca783074e8f973ac9586e6
BLAKE2b-256 662aeda2dc28e89b6a172b29bd9b1bebc759ed4f24ebc7ef31419797561af107

See more details on using hashes here.

File details

Details for the file sphinxcontrib_autoyaml-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinxcontrib_autoyaml-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 389a4f7f14e0e27abf6c705949204aeab05d0797a091cc9e66384e0699fe5376
MD5 d725ee2257a02ee0344e47c49c31464a
BLAKE2b-256 08406ed1a262f7a9db2dbd92c4e4c600f8278002b84125117860893476d088b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page