Skip to content

Commit ae1a6ce

Browse files
authored
Merge pull request #324 from huard/ext_autodoc_options
Adds docstring and skiplines options to ext_autodoc
2 parents 3f1477f + 74e0ca7 commit ae1a6ce

5 files changed

Lines changed: 38 additions & 13 deletions

File tree

docs/demobuffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self):
5959
title='Buffer',
6060
abstract='This process demonstrates, how to create any process in PyWPS environment',
6161
metadata=[Metadata('process metadata 1', 'http://example.org/1'),
62-
Metadata('process metadata 2', 'http://example.org/2')]
62+
Metadata('process metadata 2', 'http://example.org/2')],
6363
inputs=inputs,
6464
outputs=outputs,
6565
store_supported=True,

docs/external-tools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ZOO-Project
4747
client (JavaScript) framework.
4848

4949
QGIS WPS Client
50-
--------------
50+
---------------
5151

5252
The `QGIS WPS <https://plugins.qgis.org/plugins/wps/>`_ client provides a
5353
plugin with WPS support for the QGIS Desktop GIS.

docs/process.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,25 @@ To make the server visible from another computer, replace ``localhost`` with ``0
389389
Automated process documentation
390390
===============================
391391

392-
WPS :class:`Processes` can be automatically documented with `Sphinx`_ using the
392+
A :class:`Process` can be automatically documented with `Sphinx`_ using the
393393
`autoprocess` directive. The :class:`Process` object is instantiated and its
394394
content examined to create, behind the scenes, a docstring in the Numpy format. This
395395
lets developers embed the documentation directly in the code instead of having to
396-
describe each process in a separate file. For example::
396+
describe each process manually. For example::
397397

398398
.. autoprocess:: pywps.tests.DocExampleProcess
399+
:docstring:
400+
:skiplines: 1
399401

400402
would yield
401403

402404
.. autoprocess:: pywps.tests.DocExampleProcess
405+
:docstring:
406+
:skiplines: 1
407+
408+
The :option:`docstring` option fetches the :class:`Process` docstring and appends it after the
409+
Reference section. The first lines of this docstring can be skipped using the
410+
:option:`skiplines` option.
403411

404412
To use the `autoprocess` directive, first add `'sphinx.ext.napoleon'` and
405413
`'pywps.ext_autodoc'` to the list of extensions in the Sphinx configuration file

pywps/ext_autodoc.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
from sphinx.ext.autodoc import ClassDocumenter
2+
from sphinx.ext.autodoc import ClassDocumenter, bool_option
33
from sphinx.ext.napoleon.docstring import NumpyDocstring
44
from sphinx.util.docstrings import prepare_docstring
55
from sphinx.util import force_decode
6+
from docutils.parsers.rst import directives
67
from pywps import Process
78
from pywps.app.Common import Metadata
89

@@ -12,12 +13,26 @@ class ProcessDocumenter(ClassDocumenter):
1213
pywps.Process class.
1314
1415
The Process description, its inputs and docputs are converted to a
15-
numpy style docstring. Additional sections (Notes, References,
16-
Examples, etc.) can be added in the Process subclass docstring.
16+
numpy style docstring.
17+
18+
Additional sections (Notes, References, Examples, etc.) can be added
19+
in the Process subclass docstring using the `docstring` option.
20+
Additionally, docstring lines can be skipped using the `skiplines` option.
21+
22+
For, example, the following would append the SimpleProcess class docstring
23+
to the published docs, skipping the first line.
24+
25+
.. autoprocess:: pywps.SimpleProcess
26+
:docstring:
27+
:skiplines: 1
28+
1729
"""
1830
directivetype = 'class'
1931
objtype = 'process'
2032
priority = ClassDocumenter.priority + 1
33+
option_spec = {'skiplines':directives.nonnegative_int,
34+
'docstring':bool_option}
35+
option_spec.update(ClassDocumenter.option_spec)
2136

2237
@classmethod
2338
def can_document_member(cls, member, membername, isattr, parent):
@@ -96,7 +111,7 @@ class instance.
96111
for i in obj.outputs:
97112
doc.append("{} : {}".format(i.identifier, self.fmt_type(i)))
98113
doc.append(" {}".format(i.abstract or i.title))
99-
doc.append('')
114+
doc.extend(['',''])
100115

101116
# Metadata
102117
hasref = False
@@ -129,6 +144,7 @@ def get_doc(self, encoding=None, ignore=1):
129144
from six import text_type
130145
# Get the class docstring. This is a copy of the ClassDocumenter.get_doc method. Using "super" does weird stuff.
131146
docstring = self.get_attr(self.object, '__doc__', None)
147+
132148
# make sure we have Unicode docstrings, then sanitize and split
133149
# into lines
134150
if isinstance(docstring, text_type):
@@ -139,9 +155,9 @@ def get_doc(self, encoding=None, ignore=1):
139155
# Create the docstring by scraping info from the Process instance.
140156
pdocstrings = self.make_numpy_doc()
141157

142-
# Add the sections from the class itself.
143-
if docstring is not None:
144-
pdocstrings.extend(docstring)
158+
if self.options.docstring and docstring is not None:
159+
# Add the sections from the class docstring itself.
160+
pdocstrings.extend(docstring[self.options.skiplines:])
145161

146162
# Parse using the Numpy docstring format.
147163
docstrings = NumpyDocstring(pdocstrings, self.env.config, self.env.app, what='class', obj=self.object,

pywps/tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
logging.disable(logging.CRITICAL)
2020

2121
class DocExampleProcess(Process):
22-
"""
22+
"""This first line is going to be skipped by the :skiplines:1 option.
23+
2324
Notes
2425
-----
2526
26-
This is additional documentation that can be added following the numpy docstring convention.
27+
This is additional documentation that can be added following the Numpy docstring convention.
2728
"""
2829

2930
def __init__(self):

0 commit comments

Comments
 (0)