Improve handling of :module: in wsme documenters

It appears that in newer sphinx versions the index of :module:
directive in the resulting documenter object array has changed,
it is not the last element anymore. Apart from that, it is
possible to have several :module: entries in class for example.

This change fixes the issue for service, function and type
wsme documenters.

Change-Id: Icf44f8af0c1e6e70d8e921615efe03b845885be7
This commit is contained in:
Vladyslav Drok 2018-06-26 18:39:17 +03:00
parent 6dc053296f
commit f36a607124
1 changed files with 15 additions and 6 deletions

View File

@ -211,8 +211,11 @@ class TypeDocumenter(autodoc.ClassDocumenter):
def add_directive_header(self, sig):
super(TypeDocumenter, self).add_directive_header(sig)
# remove the :module: option that was added by ClassDocumenter
if ':module:' in self.directive.result[-1]:
self.directive.result.pop()
result_len = len(self.directive.result)
for index, item in zip(reversed(range(result_len)),
reversed(self.directive.result)):
if ':module:' in item:
self.directive.result.pop(index)
def import_object(self):
if super(TypeDocumenter, self).import_object():
@ -353,8 +356,11 @@ class ServiceDocumenter(autodoc.ClassDocumenter):
def add_directive_header(self, sig):
super(ServiceDocumenter, self).add_directive_header(sig)
# remove the :module: option that was added by ClassDocumenter
if ':module:' in self.directive.result[-1]:
self.directive.result.pop()
result_len = len(self.directive.result)
for index, item in zip(reversed(range(result_len)),
reversed(self.directive.result)):
if ':module:' in item:
self.directive.result.pop(index)
def format_signature(self):
return u''
@ -532,8 +538,11 @@ class FunctionDocumenter(autodoc.MethodDocumenter):
def add_directive_header(self, sig):
super(FunctionDocumenter, self).add_directive_header(sig)
# remove the :module: option that was added by ClassDocumenter
if ':module:' in self.directive.result[-1]:
self.directive.result.pop()
result_len = len(self.directive.result)
for index, item in zip(reversed(range(result_len)),
reversed(self.directive.result)):
if ':module:' in item:
self.directive.result.pop(index)
class WSMEDomain(Domain):