You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sphinx-autoapi/README.rst

183 lines
5.2 KiB
ReStructuredText

9 years ago
Sphinx AutoAPI
==============
9 years ago
.. image:: https://readthedocs.org/projects/sphinx-autoapi/badge/?version=latest
9 years ago
:target: https://sphinx-autoapi.readthedocs.org
9 years ago
:alt: Documentation Status
.. image:: https://travis-ci.org/rtfd/sphinx-autoapi.svg?branch=master
:target: https://travis-ci.org/rtfd/sphinx-autoapi
.. image:: https://ci.appveyor.com/api/projects/status/5nd33gp2eq7411t1?svg=true
:target: https://ci.appveyor.com/project/ericholscher/sphinx-autoapi
9 years ago
.. warning:: This is a pre-release version. Some or all features might not work yet.
9 years ago
9 years ago
Sphinx AutoAPI aims to provide "autodoc" or "javadoc" style documentation for Sphinx.
The aim is to support all programming languages,
be easy to use,
and not require much configuration.
9 years ago
9 years ago
AutoAPI is a parse-only solution for both static and dynamic languages.
9 years ago
This is in contrast to the traditional `Sphinx autodoc <http://sphinx-doc.org/ext/autodoc.html>`_,
9 years ago
which is Python-only and uses code imports.
9 years ago
Full documentation can be found on `Read the Docs <http://sphinx-autoapi.readthedocs.org>`_.
9 years ago
Contents
--------
.. toctree::
:caption: Main
:glob:
:maxdepth: 2
config
templates
.. toctree::
:caption: API
:glob:
:maxdepth: 2
design
9 years ago
9 years ago
Basic Workflow
--------------
Sphinx AutoAPI has the following structure:
* Configure directory to look for source files
* Serialize those source files, using language-specific tooling
* Map the serialized data into standard AutoAPI Python objects
9 years ago
* Generate RST through Jinja2 templates from those Python objects
This basic framework should be easy to implement in your language of choice.
All you need to do is be able to generate a JSON structure that includes your API and docs for those classes, functions, etc.
9 years ago
Install
-------
First you need to install autoapi:
.. code:: bash
pip install sphinx-autoapi
9 years ago
Then add it to your Sphinx project's ``conf.py``:
.. code:: python
extensions = ['autoapi.extension']
9 years ago
# Document Python Code
autoapi_type = 'python'
autoapi_dirs = ['path/to/python/files', 'path/to/more/python/files']
9 years ago
# Or, Document Go Code
autoapi_type = 'go'
autoapi_dirs = 'path/to/go/files'
AutoAPI will automatically add itself to the last TOCTree in your top-level
``index.rst``.
9 years ago
This is needed because we will be outputting rst files into the ``autoapi``
directory. This adds it into the global TOCTree for your project, so that it
appears in the menus.
We hope to be able to dynamically add items into the TOCTree, and remove this
step. However, it is currently required.
9 years ago
See all available configuration options in :doc:`config`.
Setup
-----
.NET
~~~~
The .NET mapping utilizes the tool `docfx`_. To install ``docfx``, first
you'll need to `install a .NET runtime on your system <ASP.NET Installation>`_.
The docfx tool can be installed with::
dnu commands install docfx
By default, ``docfx`` will output metadata files into the ``_api`` path. You
can configure which path to output files into using a ``docfx.json`` file in
your project's repository. Here's an example from the ASP.NET docs:
.. code:: json
{
"metadata": [{
"src": [{
"files": [
"aspnet/identity/src/\*\*/project.json"
],
"exclude": [
"aspnet/testing/src/Microsoft.AspNet.Testing/\*"
]
}],
"dest": "docs/_api",
"force": "true",
"raw": "true"
}]
}
.. note::
The ``dest`` configuration option is required to output to the ``docs/``
path, where autoapi knows to search for these files.
With a working ``docfx`` toolchain, you can now add the configuration options
to enable the .NET autoapi mapper. In your ``conf.py``:
.. code:: python
extensions = ['autoapi.extension']
autoapi_type = 'dotnet'
autoapi_dirs = ['..']
This configuration, which assumes your ``conf.py`` is in a ``docs/`` path,
will use your parent path to search for files to pass to ``docfx``. If you
have a ``docfx.json`` file present, and did not specify a custom pattern for
finding files, ``docfx.json`` will be used first.
.. _`docfx`: https://github.com/dotnet/docfx
.. _`ASP.NET Installation`: http://docs.asp.net/en/latest/getting-started/index.html
9 years ago
Customize
---------
All of the pages that AutoAPI generates are templated with Jinja2 templates.
You can fully customize how pages are displayed on a per-object basis.
Read more about it in :doc:`templates`.
Design
------
Read more about the deisgn in our :doc:`design`.
Currently Implemented
---------------------
* Python (2 only -- Epydoc doesn't support Python 3)
* .NET
9 years ago
* Go
* Javascript
9 years ago
Adding a new language
---------------------
Adding a new language should only take a couple of hours,
assuming your language has a tool to generate JSON from API documentation.
The steps to follow:
* Add a new Mapper file in `mappers/`. It's probably easiest to copy an existing one, like the Javascript or Python mappers.
* Implement the :py:func:`create_class` and :py:func:`read_file` methods on the :py:class:`SphinxMapperBase`.
* Implement all appropriate object types on the :py:class:`PythonMapperBase`
* Add a test in the `tests/test_integration.py`, along with an example project for the testing.
* Include it in the class mapping in `mappers/base.py` and `extension.py`
9 years ago