11# -*- coding: utf-8 -*-
2- from sphinx .ext .autodoc import ClassDocumenter
2+ from sphinx .ext .autodoc import ClassDocumenter , bool_option
33from sphinx .ext .napoleon .docstring import NumpyDocstring
44from sphinx .util .docstrings import prepare_docstring
55from sphinx .util import force_decode
6+ from docutils .parsers .rst import directives
67from pywps import Process
78from 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 ,
0 commit comments