diff --git a/.travis.yml b/.travis.yml index 97aae61..c066509 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,10 @@ matrix: env: TOXENV=docs # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: pip install -U tox-travis +install: + - pip install -U tox-travis + - if [[ $TRAVIS_PYTHON_VERSION == "3.3" ]]; then pip install 'virtualenv<16.0'; fi + - if [[ $TRAVIS_PYTHON_VERSION == "3.3" ]]; then pip install 'setuptools<40.0'; fi # command to run tests, e.g. python setup.py test -script: tox \ No newline at end of file +script: tox diff --git a/changelog.d/36.doc.rst b/changelog.d/36.doc.rst new file mode 100644 index 0000000..29145cb --- /dev/null +++ b/changelog.d/36.doc.rst @@ -0,0 +1 @@ +Added a documentation page demonstrating the use of the sphinx-autodocs-variants extension for displaying function groups. diff --git a/docs/conf.py b/docs/conf.py index 935c6b6..cfad161 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,9 +29,12 @@ # Insert the project root dir as the first element in the PYTHONPATH. # This lets us ensure that the source package is imported, and that its # version is used. +sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.join(project_root, 'src')) +sys.path.append(os.path.join(project_root, 'docs/examples')) import variants +import examples # -- General configuration --------------------------------------------- @@ -40,7 +43,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx_autodoc_variants'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/docs/examples/__init__.py b/docs/examples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/examples/example_variants.py b/docs/examples/example_variants.py new file mode 100644 index 0000000..d13beee --- /dev/null +++ b/docs/examples/example_variants.py @@ -0,0 +1,35 @@ +import variants + + +@variants.primary +def primary_func(x, y): + """ + This is the primary function. Its docstring should be shown under the + primary function documentation. + """ + + +@primary_func.variant('onearg') +def primary_func(x): + """This is the ``onearg`` variant, it only takes one argument.""" + + +@primary_func.variant('threearg') +def primary_func(x, y, z): + """This is the ``threearg`` variant, it takes three arguments.""" + + +class VariantMethodsClass(object): + @variants.primary + def primary_method(self, x, y): + """ + This is the primary method, its docstring should be shown under the + primary method documentation. + """ + + @primary_method.variant('onearg') + def primary_method(self, x): + """This is the ``onearg`` variant, it takes one argument.""" + + def normal_method(self, a, b): + """This is a normal method, it has no variants""" diff --git a/docs/index.rst b/docs/index.rst index 92fc67d..d2ad2b1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,6 +13,7 @@ Contents: readme installation usage + Variant Autodoc (Sphinx) <sphinx> .. toctree:: :maxdepth: 1 diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 1c03c18..40a2cdf 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,2 +1,3 @@ Sphinx sphinx_rtd_theme>=0.3.1 +sphinx-autodoc-variants diff --git a/docs/sphinx.rst b/docs/sphinx.rst new file mode 100644 index 0000000..ff7d913 --- /dev/null +++ b/docs/sphinx.rst @@ -0,0 +1,55 @@ +===================== +Documentation example +===================== + +Using the `sphinx_autodoc_variants <https://github.com/python-variants/sphinx_autodoc_variants>`_ extension, primary and variant functions can be grouped together as a single function group. + +Functions +--------- + +With the ``sphinx_autodoc_variants`` extension enabled in ``conf.py``, function groups at the module level will automatically be grouped together by the ``automodule`` directive. To explicitly document a function group, use the ``autoprimary_function`` directive: + +.. code-block:: rst + + .. autoprimary_function:: examples.example_variants.primary_func + :members: + +Which generates: + +.. autoprimary_function:: examples.example_variants.primary_func + :members: + :noindex: + + +Methods +------- +For a class containing function group methods, the ``autoclass`` directive works, so: + +.. code-block:: rst + + .. autoclass:: examples.example_variants.VariantMethodsClass + :members: + +Resulting in: + +.. autoclass:: examples.example_variants.VariantMethodsClass + :members: + :noindex: + + +As with functions, individual method groups can be documented using the ``autoprimary_method`` directive: + +.. code-block:: rst + + .. autoprimary_method:: examples.example_variants.VariantMethodsClass.primary_method + :members: + +Which generates: + +.. autoprimary_method:: examples.example_variants.VariantMethodsClass.primary_method + :members: + + +.. .. automodule:: examples.example_variants +.. :members: +.. :undoc-members: