diff -r 9986ec0e559a -r 10516539f238 DocumentationTools/ModuleDocumentor.py --- a/DocumentationTools/ModuleDocumentor.py Tue Oct 15 22:03:54 2013 +0200 +++ b/DocumentationTools/ModuleDocumentor.py Fri Oct 18 23:00:41 2013 +0200 @@ -52,6 +52,7 @@ """ Exception class raised, if an invalid documentation tag was found. """ + pass class ModuleDocument(object): @@ -80,56 +81,75 @@ self.rbFileTemplate = TemplatesListsStyleCSS.rbFileTemplate self.classTemplate = TemplatesListsStyleCSS.classTemplate self.methodTemplate = TemplatesListsStyleCSS.methodTemplate - self.constructorTemplate = TemplatesListsStyleCSS.constructorTemplate + self.constructorTemplate = \ + TemplatesListsStyleCSS.constructorTemplate self.rbModuleTemplate = TemplatesListsStyleCSS.rbModuleTemplate - self.rbModulesClassTemplate = TemplatesListsStyleCSS.rbModulesClassTemplate + self.rbModulesClassTemplate = \ + TemplatesListsStyleCSS.rbModulesClassTemplate self.functionTemplate = TemplatesListsStyleCSS.functionTemplate self.listTemplate = TemplatesListsStyleCSS.listTemplate self.listEntryTemplate = TemplatesListsStyleCSS.listEntryTemplate - self.listEntryNoneTemplate = TemplatesListsStyleCSS.listEntryNoneTemplate + self.listEntryNoneTemplate = \ + TemplatesListsStyleCSS.listEntryNoneTemplate self.listEntryDeprecatedTemplate = \ TemplatesListsStyleCSS.listEntryDeprecatedTemplate - self.listEntrySimpleTemplate = TemplatesListsStyleCSS.listEntrySimpleTemplate + self.listEntrySimpleTemplate = \ + TemplatesListsStyleCSS.listEntrySimpleTemplate self.paragraphTemplate = TemplatesListsStyleCSS.paragraphTemplate - self.parametersListTemplate = TemplatesListsStyleCSS.parametersListTemplate + self.parametersListTemplate = \ + TemplatesListsStyleCSS.parametersListTemplate self.parametersListEntryTemplate = \ TemplatesListsStyleCSS.parametersListEntryTemplate self.returnsTemplate = TemplatesListsStyleCSS.returnsTemplate - self.exceptionsListTemplate = TemplatesListsStyleCSS.exceptionsListTemplate + self.exceptionsListTemplate = \ + TemplatesListsStyleCSS.exceptionsListTemplate self.exceptionsListEntryTemplate = \ TemplatesListsStyleCSS.exceptionsListEntryTemplate - self.signalsListTemplate = TemplatesListsStyleCSS.signalsListTemplate + self.signalsListTemplate = \ + TemplatesListsStyleCSS.signalsListTemplate self.signalsListEntryTemplate = \ TemplatesListsStyleCSS.signalsListEntryTemplate self.eventsListTemplate = TemplatesListsStyleCSS.eventsListTemplate - self.eventsListEntryTemplate = TemplatesListsStyleCSS.eventsListEntryTemplate + self.eventsListEntryTemplate = \ + TemplatesListsStyleCSS.eventsListEntryTemplate self.deprecatedTemplate = TemplatesListsStyleCSS.deprecatedTemplate self.authorInfoTemplate = TemplatesListsStyleCSS.authorInfoTemplate self.seeListTemplate = TemplatesListsStyleCSS.seeListTemplate - self.seeListEntryTemplate = TemplatesListsStyleCSS.seeListEntryTemplate + self.seeListEntryTemplate = \ + TemplatesListsStyleCSS.seeListEntryTemplate self.seeLinkTemplate = TemplatesListsStyleCSS.seeLinkTemplate self.sinceInfoTemplate = TemplatesListsStyleCSS.sinceInfoTemplate else: from . import TemplatesListsStyle - self.headerTemplate = TemplatesListsStyle.headerTemplate.format(**colors) - self.footerTemplate = TemplatesListsStyle.footerTemplate.format(**colors) - self.moduleTemplate = TemplatesListsStyle.moduleTemplate.format(**colors) - self.rbFileTemplate = TemplatesListsStyle.rbFileTemplate.format(**colors) - self.classTemplate = TemplatesListsStyle.classTemplate.format(**colors) - self.methodTemplate = TemplatesListsStyle.methodTemplate.format(**colors) + self.headerTemplate = \ + TemplatesListsStyle.headerTemplate.format(**colors) + self.footerTemplate = \ + TemplatesListsStyle.footerTemplate.format(**colors) + self.moduleTemplate = \ + TemplatesListsStyle.moduleTemplate.format(**colors) + self.rbFileTemplate = \ + TemplatesListsStyle.rbFileTemplate.format(**colors) + self.classTemplate = \ + TemplatesListsStyle.classTemplate.format(**colors) + self.methodTemplate = \ + TemplatesListsStyle.methodTemplate.format(**colors) self.constructorTemplate = \ TemplatesListsStyle.constructorTemplate.format(**colors) - self.rbModuleTemplate = TemplatesListsStyle.rbModuleTemplate.format(**colors) + self.rbModuleTemplate = \ + TemplatesListsStyle.rbModuleTemplate.format(**colors) self.rbModulesClassTemplate = \ TemplatesListsStyle.rbModulesClassTemplate.format(**colors) - self.functionTemplate = TemplatesListsStyle.functionTemplate.format(**colors) - self.listTemplate = TemplatesListsStyle.listTemplate.format(**colors) + self.functionTemplate = \ + TemplatesListsStyle.functionTemplate.format(**colors) + self.listTemplate = \ + TemplatesListsStyle.listTemplate.format(**colors) self.listEntryTemplate = \ TemplatesListsStyle.listEntryTemplate.format(**colors) self.listEntryNoneTemplate = \ TemplatesListsStyle.listEntryNoneTemplate.format(**colors) self.listEntryDeprecatedTemplate = \ - TemplatesListsStyle.listEntryDeprecatedTemplate.format(**colors) + TemplatesListsStyle.listEntryDeprecatedTemplate.format( + **colors) self.listEntrySimpleTemplate = \ TemplatesListsStyle.listEntrySimpleTemplate.format(**colors) self.paragraphTemplate = \ @@ -137,12 +157,15 @@ self.parametersListTemplate = \ TemplatesListsStyle.parametersListTemplate.format(**colors) self.parametersListEntryTemplate = \ - TemplatesListsStyle.parametersListEntryTemplate.format(**colors) - self.returnsTemplate = TemplatesListsStyle.returnsTemplate.format(**colors) + TemplatesListsStyle.parametersListEntryTemplate.format( + **colors) + self.returnsTemplate = \ + TemplatesListsStyle.returnsTemplate.format(**colors) self.exceptionsListTemplate = \ TemplatesListsStyle.exceptionsListTemplate.format(**colors) self.exceptionsListEntryTemplate = \ - TemplatesListsStyle.exceptionsListEntryTemplate.format(**colors) + TemplatesListsStyle.exceptionsListEntryTemplate.format( + **colors) self.signalsListTemplate = \ TemplatesListsStyle.signalsListTemplate.format(**colors) self.signalsListEntryTemplate = \ @@ -155,20 +178,24 @@ TemplatesListsStyle.deprecatedTemplate.format(**colors) self.authorInfoTemplate = \ TemplatesListsStyle.authorInfoTemplate.format(**colors) - self.seeListTemplate = TemplatesListsStyle.seeListTemplate.format(**colors) + self.seeListTemplate = \ + TemplatesListsStyle.seeListTemplate.format(**colors) self.seeListEntryTemplate = \ TemplatesListsStyle.seeListEntryTemplate.format(**colors) - self.seeLinkTemplate = TemplatesListsStyle.seeLinkTemplate.format(**colors) + self.seeLinkTemplate = \ + TemplatesListsStyle.seeLinkTemplate.format(**colors) self.sinceInfoTemplate = \ TemplatesListsStyle.sinceInfoTemplate.format(**colors) - self.keywords = [] # list of tuples containing the name (string) and - # the ref (string). The ref is without the filename part. + self.keywords = [] + # list of tuples containing the name (string) and + # the ref (string). The ref is without the filename part. self.generated = False def isEmpty(self): """ - Public method to determine, if the module contains any classes or functions. + Public method to determine, if the module contains any classes or + functions. @return Flag indicating an empty module (i.e. __init__.py without any contents) @@ -247,7 +274,8 @@ 'FunctionList': functionList, }) except TagError as e: - sys.stderr.write("Error in tags of description of module {0}.\n".format( + sys.stderr.write( + "Error in tags of description of module {0}.\n".format( self.module.name)) sys.stderr.write("{0}\n".format(e)) return "" @@ -275,8 +303,10 @@ lst.append(self.listEntryTemplate.format(**{ \ 'Link': "{0}".format(name), 'Name': dict[name].name, - 'Description': self.__getShortDescription(dict[name].description), - 'Deprecated': self.__checkDeprecated(dict[name].description) and \ + 'Description': + self.__getShortDescription(dict[name].description), + 'Deprecated': + self.__checkDeprecated(dict[name].description) and \ self.listEntryDeprecatedTemplate or "", })) if kwSuffix: @@ -313,7 +343,8 @@ def __genClassListSection(self): """ - Private method to generate the section listing all classes of the module. + Private method to generate the section listing all classes of the + module. @return The classes list section. (string) """ @@ -346,7 +377,8 @@ def __genFunctionListSection(self): """ - Private method to generate the section listing all functions of the module. + Private method to generate the section listing all functions of the + module. @return The functions list section. (string) """ @@ -362,7 +394,8 @@ def __genClassesSection(self): """ - Private method to generate the document section with details about classes. + Private method to generate the document section with details about + classes. @return The classes details section. (string) """ @@ -389,15 +422,18 @@ 'Anchor': className, 'Class': _class.name, 'ClassSuper': supers, - 'ClassDescription': self.__formatDescription(_class.description), + 'ClassDescription': + self.__formatDescription(_class.description), 'GlobalsList': globalsList, 'ClassMethodList': classMethList, 'MethodList': methList, 'StaticMethodList': staticMethList, - 'MethodDetails': classMethBodies + methBodies + staticMethBodies, + 'MethodDetails': + classMethBodies + methBodies + staticMethBodies, }) except TagError as e: - sys.stderr.write("Error in tags of description of class {0}.\n".format( + sys.stderr.write( + "Error in tags of description of class {0}.\n".format( className)) sys.stderr.write("{0}\n".format(e)) clsBody = "" @@ -415,7 +451,8 @@ @param dict dictionary containing all relevant information @param className class name containing the names @param clsName visible class name containing the names - @param includeInit flag indicating to include the __init__ method (boolean) + @param includeInit flag indicating to include the __init__ method + (boolean) @return methods list section (string) """ lst = [] @@ -430,8 +467,9 @@ dict['__init__'].description) and \ self.listEntryDeprecatedTemplate or "", })) - self.keywords.append(("{0} (Constructor)".format(className), - "#{0}.{1}".format(className, '__init__'))) + self.keywords.append( + ("{0} (Constructor)".format(className), + "#{0}.{1}".format(className, '__init__'))) except KeyError: pass @@ -439,9 +477,11 @@ lst.append(self.listEntryTemplate.format(**{ \ 'Link': "{0}.{1}".format(className, name), 'Name': dict[name].name, - 'Description': self.__getShortDescription(dict[name].description), - 'Deprecated': self.__checkDeprecated(dict[name].description) and \ - self.listEntryDeprecatedTemplate or "", + 'Description': + self.__getShortDescription(dict[name].description), + 'Deprecated': + self.__checkDeprecated(dict[name].description) and \ + self.listEntryDeprecatedTemplate or "", })) self.keywords.append(("{0}.{1}".format(className, name), "#{0}.{1}".format(className, name))) @@ -468,8 +508,10 @@ 'Class': obj.name, 'Method': '__init__', 'MethodDescription': \ - self.__formatDescription(obj.methods['__init__'].description), - 'Params': ', '.join(obj.methods['__init__'].parameters[1:]), + self.__formatDescription( + obj.methods['__init__'].description), + 'Params': + ', '.join(obj.methods['__init__'].parameters[1:]), }) except TagError as e: sys.stderr.write( @@ -492,8 +534,9 @@ 'Class': obj.name, 'Method': obj.methods[method].name, 'MethodClassifier': methodClassifier, - 'MethodDescription': \ - self.__formatDescription(obj.methods[method].description), + 'MethodDescription': + self.__formatDescription( + obj.methods[method].description), 'Params': ', '.join(obj.methods[method].parameters[1:]), }) except TagError as e: @@ -504,8 +547,8 @@ methBody = "" methBodies.append(methBody) - methList = self.__genMethodsListSection(methods, obj.methods, className, - obj.name, includeInit=filter == Function.General) + methList = self.__genMethodsListSection(methods, obj.methods, + className, obj.name, includeInit=filter == Function.General) if not methList: methList = self.listEntryNoneTemplate @@ -515,7 +558,8 @@ def __genRbModulesSection(self): """ - Private method to generate the document section with details about Ruby modules. + Private method to generate the document section with details about + Ruby modules. @return The Ruby modules details section. (string) """ @@ -524,16 +568,17 @@ for rbModuleName in rbModulesNames: rbModule = self.module.modules[rbModuleName] globalsList = self.__genGlobalsListSection(rbModule) - methList, methBodies = \ - self.__genMethodSection(rbModule, rbModuleName, Function.General) - classList, classBodies = \ - self.__genRbModulesClassesSection(rbModule, rbModuleName) + methList, methBodies = self.__genMethodSection( + rbModule, rbModuleName, Function.General) + classList, classBodies = self.__genRbModulesClassesSection( + rbModule, rbModuleName) try: rbmBody = self.rbModuleTemplate.format(**{ \ 'Anchor': rbModuleName, 'Module': rbModule.name, - 'ModuleDescription': self.__formatDescription(rbModule.description), + 'ModuleDescription': + self.__formatDescription(rbModule.description), 'GlobalsList': globalsList, 'ClassesList': classList, 'ClassesDetails': classBodies, @@ -542,8 +587,8 @@ }) except TagError as e: sys.stderr.write( - "Error in tags of description of Ruby module {0}.\n".format( - rbModuleName)) + "Error in tags of description of Ruby module {0}.\n" + .format(rbModuleName)) sys.stderr.write("{0}\n".format(e)) rbmBody = "" @@ -557,7 +602,8 @@ @param obj Reference to the object being formatted. @param modName Name of the Ruby module containing the classes. (string) - @return The classes list and classes details section. (tuple of two string) + @return The classes list and classes details section. + (tuple of two string) """ classNames = sorted(list(obj.classes.keys())) classes = [] @@ -577,20 +623,22 @@ 'Anchor': className, 'Class': _class.name, 'ClassSuper': supers, - 'ClassDescription': self.__formatDescription(_class.description), + 'ClassDescription': + self.__formatDescription(_class.description), 'MethodList': methList, 'MethodDetails': methBodies, }) except TagError as e: - sys.stderr.write("Error in tags of description of class {0}.\n".format( + sys.stderr.write( + "Error in tags of description of class {0}.\n".format( className)) sys.stderr.write("{0}\n".format(e)) clsBody = "" classes.append(clsBody) - classesList = \ - self.__genRbModulesClassesListSection(classNames, obj.classes, modName) + classesList = self.__genRbModulesClassesListSection( + classNames, obj.classes, modName) if not classesList: classesList = self.listEntryNoneTemplate @@ -604,7 +652,8 @@ @param names The names to appear in the list. (list of strings) @param dict A dictionary containing all relevant information. - @param moduleName Name of the Ruby module containing the classes. (string) + @param moduleName Name of the Ruby module containing the classes. + (string) @return The list section. (string) """ lst = [] @@ -612,9 +661,11 @@ lst.append(self.listEntryTemplate.format(**{ \ 'Link': "{0}.{1}".format(moduleName, name), 'Name': dict[name].name, - 'Description': self.__getShortDescription(dict[name].description), - 'Deprecated': self.__checkDeprecated(dict[name].description) and \ - self.listEntryDeprecatedTemplate or "", + 'Description': + self.__getShortDescription(dict[name].description), + 'Deprecated': + self.__checkDeprecated(dict[name].description) and \ + self.listEntryDeprecatedTemplate or "", })) self.keywords.append(("{0}.{1}".format(moduleName, name), "#{0}.{1}".format(moduleName, name))) @@ -622,7 +673,8 @@ def __genFunctionsSection(self): """ - Private method to generate the document section with details about functions. + Private method to generate the document section with details about + functions. @return The functions details section. (string) """ @@ -635,10 +687,12 @@ 'Function': self.module.functions[funcName].name, 'FunctionDescription': self.__formatDescription( self.module.functions[funcName].description), - 'Params': ', '.join(self.module.functions[funcName].parameters), + 'Params': + ', '.join(self.module.functions[funcName].parameters), }) except TagError as e: - sys.stderr.write("Error in tags of description of function {0}.\n".format( + sys.stderr.write( + "Error in tags of description of function {0}.\n".format( funcName)) sys.stderr.write("{0}\n".format(e)) funcBody = "" @@ -668,8 +722,10 @@ if dotpos == -1: sdlist.append(desc.strip()) else: - while dotpos + 1 < len(desc) and not desc[dotpos + 1].isspace(): - # don't recognize '.' inside a number or word as stop condition + while dotpos + 1 < len(desc) and \ + not desc[dotpos + 1].isspace(): + # don't recognize '.' inside a number or word as + # stop condition dotpos = desc.find('.', dotpos + 1) if dotpos == -1: break @@ -691,8 +747,8 @@ Private method to check, if the object to be documented contains a deprecated flag. - @param desc The documentation string. (string) - @return Flag indicating the deprecation status. (boolean) + @param descr documentation string (string) + @return flag indicating the deprecation status (boolean) """ dlist = descr.splitlines() for desc in dlist: @@ -801,7 +857,8 @@ def __genSeeListSection(self, _list, template): """ - Private method to generate the "see also" list section of a description. + Private method to generate the "see also" list section of a + description. @param _list List containing the info for the section. @param template The template to be used for the list. (string) @@ -811,7 +868,8 @@ for seeEntry in _list: seeEntryString = ''.join(seeEntry) lst.append(template.format(**{ \ - 'Link': html_uencode(self.__formatCrossReferenceEntry(seeEntryString)), + 'Link': html_uencode(self.__formatCrossReferenceEntry( + seeEntryString)), })) return '\n'.join(lst) @@ -821,6 +879,7 @@ @param desc One line of the description (string) @return processed line with inline tags expanded (string) + @exception TagError raised to indicate an invalid tag """ start = desc.find('{@') while start != -1: @@ -832,15 +891,17 @@ if tagText.startswith('@link'): parts = tagText.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in inline tag {0}.\n{1}".format( - parts[0], desc)) + raise TagError( + "Wrong format in inline tag {0}.\n{1}".format( + parts[0], desc)) formattedTag = self.__formatCrossReferenceEntry(parts[1]) desc = desc.replace("{{{0}}}".format(tagText), formattedTag) else: tag = tagText.split(None, 1)[0] - raise TagError("Unknown inline tag encountered, {0}.\n{1}".format( - tag, desc)) + raise TagError( + "Unknown inline tag encountered, {0}.\n{1}".format( + tag, desc)) start = desc.find('{@') @@ -878,11 +939,12 @@ ditem = self.__processInlineTags(ditem) desc = ditem.strip() if desc: - if desc.startswith("@param") or desc.startswith("@keyparam"): + if desc.startswith(("@param", "@keyparam")): inTagSection = True parts = desc.split(None, 2) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) paramName = parts[1] if parts[0] == "@keyparam": paramName += '=' @@ -891,20 +953,20 @@ except IndexError: paramList.append([paramName, []]) lastItem = paramList[-1][1] - elif desc.startswith("@return"): + elif desc.startswith(("@return", "@ireturn")): inTagSection = True parts = desc.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) returns = [parts[1]] lastItem = returns - elif desc.startswith("@exception") or \ - desc.startswith("@throws") or \ - desc.startswith("@raise"): + elif desc.startswith(("@exception", "@throws", "@raise")): inTagSection = True parts = desc.split(None, 2) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) excName = parts[1] try: exceptionDict[excName] = [parts[2]] @@ -928,7 +990,8 @@ inTagSection = True m = _event(desc, 0) if m is None: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) eventName = 1 and m.group("EventName1") \ or m.group("EventName2") eventDesc = 1 and m.group("EventDescription1") \ @@ -941,35 +1004,40 @@ inTagSection = True parts = desc.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) deprecated = [parts[1]] lastItem = deprecated elif desc.startswith("@author"): inTagSection = True parts = desc.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) authorInfo = [parts[1]] lastItem = authorInfo elif desc.startswith("@since"): inTagSection = True parts = desc.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) sinceInfo = [parts[1]] lastItem = sinceInfo elif desc.startswith("@see"): inTagSection = True parts = desc.split(None, 1) if len(parts) < 2: - raise TagError("Wrong format in {0} line.\n".format(parts[0])) + raise TagError( + "Wrong format in {0} line.\n".format(parts[0])) seeList.append([parts[1]]) lastItem = seeList[-1] elif desc.startswith("@@"): lastItem.append(desc[1:]) elif desc.startswith("@"): tag = desc.split(None, 1)[0] - raise TagError("Unknown tag encountered, {0}.\n".format(tag)) + raise TagError( + "Unknown tag encountered, {0}.\n".format(tag)) else: lastItem.append(ditem) elif not inTagSection: @@ -989,7 +1057,8 @@ parameterSect = "" if returns: - returnSect = self.returnsTemplate.format(html_uencode('\n'.join(returns))) + returnSect = self.returnsTemplate.format( + html_uencode('\n'.join(returns))) else: returnSect = "" @@ -1040,7 +1109,8 @@ if seeList: seeSect = self.seeListTemplate.format(**{ \ - 'Links': self.__genSeeListSection(seeList, self.seeListEntryTemplate), + 'Links': self.__genSeeListSection( + seeList, self.seeListEntryTemplate), }) else: seeSect = '' @@ -1055,8 +1125,8 @@ """ Public method to retrieve the parts for the QtHelp keywords section. - @return list of tuples containing the name (string) and the ref (string). The ref - is without the filename part. + @return list of tuples containing the name (string) and the ref + (string). The ref is without the filename part. """ if not self.generated: self.genDocument()