Skip to main content

Sphinx plugin for generating documentation from ASDF schemas

Project description

CI Status

sphinx-asdf is a plugin for sphinx that enables generation of documentation from ASDF schemas.

Installation

To install the latest release on PyPI:

$ pip install sphinx-asdf

The latest development version is available from the main branch on github. To clone the project:

$ git clone https://github.com/asdf-format/sphinx-asdf

To install:

$ cd sphinx-asdf
$ pip install .

To install in development mode:

$ pip install -e .

Usage

The sphinx-asdf plugin provides two sphinx directives, asdf-autoschemas and asdf-schema.

The plugin also provides several configuration variables:

  • asdf_schema_path

  • asdf_schema_standard_prefix

  • asdf_schema_reference_mappings

Basic Example

Consider a package with the following layout as an example:

mypackage/
   setup.py
   mypackage/
      schemas/
         example.org/
            custom/
               foo/
                  a.yaml
                  b.yaml
                  c.yaml
               bar/
                  x.yaml
                  y.yaml
                  z.yaml
      ...
   docs/
      conf.py
      schemas.rst

This package provides schemas with tags that all have the prefix of tag:example.org/custom. The layout of the schema directory reflects this naming convention. We wish to provide documentation for all of our schemas.

First, we will add configuration variables to our docs/conf.py file:

# This variable indicates the top-level directory containing schemas.
# The path is relative to the location of conf.py in the package
asdf_schema_path = "../mypackage/schemas"
# This variable indicates the standard prefix that is common to all schemas
# provided by the package.
asdf_schema_standard_prefix = "example.org/custom"

The variables set in the docs/conf.py file indicate to sphinx-asdf where to locate the schemas based on the names we will use in the documentation.

Now, we use the asdf-autoschemas directive in docs/schemas.rst to create a table of contents for the schema documentation:

.. asdf-autoschemas::

   foo/a
   foo/b
   foo/c
   bar/x
   bar/y
   bar/z

Each item in the list represents the name of a schema to be included in the documents. The names are not paths to the schema files and should not include the file extension. Resolution of the names to actual schema files is handled by the asdf_schema_path and asdf_schema_standard_prefix configuration variables.

We can also use multiple asdf-autoschemas directives if we wish:

These schemas are part of foo:

.. asdf-autoschemas::

   foo/a
   foo/b
   foo/c

And these schemas are part of bar:

.. asdf-autoschemas::

   bar/x
   bar/y
   bar/z

When sphinx-build runs, the sphinx-asdf plugin will automatically generate schema documentation for each of the schemas listed in each asdf-autoschemas directive. In the documentation, each asdf-autoschemas directive will be replaced with a table of contents that contains links to each of the listed schema documents.

Directive settings

While the asdf_schema_path and asdf_schema_standard_prefix configuration variables set global schema resolution settings, it is also possible to set per-directive settings. For example, we could have done the following:

.. asdf-autoschemas::
   :schema_root: ../mypackage/schemas
   :standard_prefix: example.org/custom

This would eliminate the need to set global settings. It also allows any global settings to be overridden on a per-directive basis.

External References

Schema references to other schemas in the same package are automatically converted to links in the generated documentation. (This assumes that all of the references correspond to schemas that are explicitly generated by an asdf-autoschemas directive). However, sometimes it is necessary to resolve references to schemas in other packages. The asdf_schema_reference_mapping configuration variable is provided for this purpose. It enables a mapping between references that begin with a particular prefix to a URL indicating another package’s documentation.

For example, to enable references to the ASDF Standard documentation to be resolved as links, include the following in your docs/conf.py file:

asdf_schema_reference_mappings = [
    ('tag:stsci.edu:asdf',
     'http://asdf-standard.readthedocs.io/en/latest/generated/stsci.edu/asdf/'),
]

Inline documentation

The asdf-autoschemas directive automatically generates individual schema documentation pages and creates a table of contents. However, sometimes it may be useful to include schema documentation inline inside another document. The asdf-schema directive is provided for this purpose.

Using the package described above as an example, the asdf-schema directive can be used to document a single schema inside of another document:

.. asdf-schema::

   foo/a

The behavior of the asdf-schema directive is also governed by the asdf_schema_path and asdf_schema_standard_prefix global configuration variables. The directive also accepts the same :schema_root: and :standard_prefix: arguments as asdf-autoschemas (see Directive settings above) for per-directive configuration.

Contributing

We welcome feedback and contributions to the project. Contributions of code, documentation, or general feedback are all appreciated. Please follow the contributing guidelines to submit an issue or a pull request.

We strive to provide a welcoming community to all of our users by abiding to the Code of Conduct.

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

sphinx-asdf-0.2.2.tar.gz (55.1 kB view details)

Uploaded Source

Built Distribution

sphinx_asdf-0.2.2-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file sphinx-asdf-0.2.2.tar.gz.

File metadata

  • Download URL: sphinx-asdf-0.2.2.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sphinx-asdf-0.2.2.tar.gz
Algorithm Hash digest
SHA256 44b3d4829df90bf2f9d0dadfd6a1fe1522c040842cd3c61ff4717edd85d0860e
MD5 64b8106205c7d00dd7683d152c4b4e0e
BLAKE2b-256 c49d16aa3293a6eb13d2f36eafc1b39be8264f993f9febb3ef2d8ba1bb15e64e

See more details on using hashes here.

File details

Details for the file sphinx_asdf-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: sphinx_asdf-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sphinx_asdf-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 760f7c0e5271176825c0a327ad70abce40f83394ef99e7dbe576392e30b04480
MD5 df8d30cdc4465fed0c073c6b4aa9de20
BLAKE2b-256 352da2eab804c9fdf8d6f00392aeff4229b1cc61e4992a953b3d5d8665332840

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