2013-04-12 22:09:00 +02:00
|
|
|
# vim:fileencoding=utf-8:noet
|
2013-03-17 17:20:21 +01:00
|
|
|
from sphinx.ext import autodoc
|
2013-04-12 22:09:00 +02:00
|
|
|
from inspect import formatargspec
|
|
|
|
from powerline.lint.inspect import getconfigargspec
|
|
|
|
from powerline.lib.threaded import ThreadedSegment
|
2013-03-17 17:20:21 +01:00
|
|
|
|
2013-03-17 19:26:57 +01:00
|
|
|
try:
|
|
|
|
from __builtin__ import unicode
|
|
|
|
except ImportError:
|
2013-03-24 16:59:56 +01:00
|
|
|
unicode = lambda s, enc: s # NOQA
|
2013-03-17 19:26:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
def formatvalue(val):
|
|
|
|
if type(val) is str:
|
|
|
|
return '="' + unicode(val, 'utf-8').replace('"', '\\"').replace('\\', '\\\\') + '"'
|
|
|
|
else:
|
|
|
|
return '=' + repr(val)
|
|
|
|
|
2013-03-17 17:20:21 +01:00
|
|
|
|
|
|
|
class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
|
|
|
'''Specialized documenter subclass for ThreadedSegment subclasses.'''
|
|
|
|
@classmethod
|
|
|
|
def can_document_member(cls, member, membername, isattr, parent):
|
|
|
|
return (isinstance(member, ThreadedSegment) or
|
|
|
|
super(ThreadedDocumenter, cls).can_document_member(member, membername, isattr, parent))
|
|
|
|
|
|
|
|
def format_args(self):
|
2013-04-12 22:09:00 +02:00
|
|
|
argspec = getconfigargspec(self.object)
|
2013-03-17 19:26:57 +01:00
|
|
|
return formatargspec(*argspec, formatvalue=formatvalue).replace('\\', '\\\\')
|
2013-03-17 17:20:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
def setup(app):
|
|
|
|
autodoc.setup(app)
|
|
|
|
app.add_autodocumenter(ThreadedDocumenter)
|