def get_doc(self, encoding=None, ignore=1): """Reimplemented to include data from the call method""" content = self.env.config.autodata_content if content not in ('both', 'call') or not self.get_attr( self.get_attr(self.object, '__call__', None), '__doc__'): return super(CallableAttributeDocumenter, self).get_doc( encoding=encoding, ignore=ignore) # for classes, what the "docstring" is can be controlled via a # config value; the default is both docstrings docstrings = [] if content != 'call': docstring = self.get_attr(self.object, '__doc__', None) docstrings = [docstring + '\n'] if docstring else [] calldocstring = self.get_attr( self.get_attr(self.object, '__call__', None), '__doc__') if docstrings: docstrings[0] += calldocstring else: docstrings.append(calldocstring + '\n') doc = [] for docstring in docstrings: if not isinstance(docstring, six.text_type): docstring = force_decode(docstring, encoding) doc.append(prepare_docstring(docstring, ignore)) return doc
def _gen () : own = map.OWN if map.__doc__ and own : yield autodoc.prepare_docstring (map.__doc__) for k, v in sorted (own) : vs = list (" %s" % (l, ) for l in v.split ("\n")) yield [".. attribute:: %s" % k, ""] + vs
def nodes_for_route(self, route, view): '''Create nodes for a single route''' env = self.state.document.settings.env doc = '\n'.join(prepare_docstring(view.__doc__)) # Reset values for rest api and rest config env.config._rest_api = None env.config._rest_config = None # Get rest api from possible use of .. rest_api:: self.parse_string(doc) config = env.config._rest_config context = env.config._rest_api if not context: context = {} # Default view, route and doc in context context['doc'] = doc context['view'] = view context['route'] = route # Use event to add any other context for the template env.app.emit('modify-rest-api', route, view, config, context) # Get template and render restructured text using context template_env = self.get_template_env() template = template_env.get_template("rest_api/default.rst") string = template.render(api=context) # Return nodes from parsing the restructured text return self.parse_string(string)
def _e_type_attr_doc (self, doc, indent) : result = [] if doc : result = autodoc.prepare_docstring (doc) if indent : result = [((indent + l) if l else l) for l in result] return result
def get_doc(self, encoding=None, ignore=1): """Reimplemented to include data from the call method""" content = self.env.config.autodata_content if content not in ('both', 'call') or not self.get_attr( self.get_attr(self.object, '__call__', None), '__doc__'): return super(CallableDataDocumenter, self).get_doc( encoding=encoding, ignore=ignore) # for classes, what the "docstring" is can be controlled via a # config value; the default is both docstrings docstrings = [] if content != 'call': docstring = self.get_attr(self.object, '__doc__', None) docstrings = [docstring + '\n'] if docstring else [] calldocstring = self.get_attr( self.get_attr(self.object, '__call__', None), '__doc__') if docstrings: docstrings[0] += calldocstring else: docstrings.append(calldocstring + '\n') doc = [] for docstring in docstrings: if not isinstance(docstring, six.text_type): docstring = force_decode(docstring, encoding) doc.append(prepare_docstring(docstring, ignore)) return doc
def run(self): module = _resolve_dotted_name(self.module) if not getattr(module, '__file__', None): raise 'No module found for: ' + self.module module_path = os.path.abspath(os.path.dirname(module.__file__)) doc_path = module_path + self.doc if not os.path.isfile(doc_path): raise 'No doc found for: ' + doc_path result = ViewList() result.append(u'', '<includedoc>') #for i, line in enumerate(get_doc(what, self.module+':'+self+doc, todoc, options, env)): for i, line in enumerate(prepare_docstring(open(doc_path).read())): result.append(line, '%s:docstring of %s' % (self.doc, self.module), i) result.append(u'', '<includedoc>') node = section() surrounding_title_styles = self.state.memo.title_styles surrounding_section_level = self.state.memo.section_level self.state.memo.title_styles = [] self.state.memo.section_level = 0 self.state.nested_parse(result, 0, node, match_titles=1) self.state.memo.title_styles = surrounding_title_styles self.state.memo.section_level = surrounding_section_level return node.children
def __init__(self, text): # # Skip the pre-processing if we already have a Docstring if isinstance(text, Docstring): rawdoc = text # Use autodoc.prepare_docstring on strings elif isinstance(text, str): rawdoc = autodoc.prepare_docstring(text) # Careful: prepare_docstring adds an extra blank line... rawdoc.pop(-1) # A StringList or a list: make sure that we don't start with empty lines elif isinstance(text, (list, StringList)): rawdoc = text while rawdoc and not rawdoc[0]: rawdoc.pop(0) # list.__init__(self, rawdoc)
def __init__(self, text): # # Skip the pre-processing if we already have a Docstring if isinstance(text, Docstring): rawdoc = text # Use autodoc.prepare_docstring on strings elif isinstance(text, basestring): rawdoc = autodoc.prepare_docstring(text) # Careful: prepare_docstring adds an extra blank line... rawdoc.pop(-1) # A StringList or a list: make sure that we don't start with empty lines elif isinstance(text, (list, StringList)): rawdoc = text while rawdoc and not rawdoc[0]: rawdoc.pop(0) # list.__init__(self, rawdoc)
def _e_type_doc_x (self, ET, name) : result = [] doc = getattr (ET, name, None) if doc is not None : result = [autodoc.prepare_docstring (doc)] return result