eric6/DocumentationTools/ModuleDocumentor.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8257
28146736bbfc
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
11 this module. 11 this module.
12 """ 12 """
13 13
14 import sys 14 import sys
15 import re 15 import re
16 import contextlib
16 17
17 from Utilities import html_uencode 18 from Utilities import html_uencode
18 from Utilities.ModuleParser import RB_SOURCE, Function 19 from Utilities.ModuleParser import RB_SOURCE, Function
19 20
20 _signal = re.compile( 21 _signal = re.compile(
53 Exception class raised, if an invalid documentation tag was found. 54 Exception class raised, if an invalid documentation tag was found.
54 """ 55 """
55 pass 56 pass
56 57
57 58
58 class ModuleDocument(object): 59 class ModuleDocument:
59 """ 60 """
60 Class implementing the builtin documentation generator. 61 Class implementing the builtin documentation generator.
61 """ 62 """
62 def __init__(self, module, colors, stylesheet=None): 63 def __init__(self, module, colors, stylesheet=None):
63 """ 64 """
301 sys.stderr.write("{0}\n".format(e)) 302 sys.stderr.write("{0}\n".format(e))
302 return "" 303 return ""
303 304
304 classesSection = self.__genClassesSection() 305 classesSection = self.__genClassesSection()
305 functionsSection = self.__genFunctionsSection() 306 functionsSection = self.__genFunctionsSection()
306 if self.module.type == RB_SOURCE: 307 rbModulesSection = (
307 rbModulesSection = self.__genRbModulesSection() 308 self.__genRbModulesSection()
308 else: 309 if self.module.type == RB_SOURCE else
309 rbModulesSection = "" 310 ""
311 )
310 return "{0}{1}{2}{3}".format( 312 return "{0}{1}{2}{3}".format(
311 modBody, classesSection, rbModulesSection, functionsSection) 313 modBody, classesSection, rbModulesSection, functionsSection)
312 314
313 def __genListSection(self, names, sectionDict, kwSuffix=""): 315 def __genListSection(self, names, sectionDict, kwSuffix=""):
314 """ 316 """
329 self.__getShortDescription(sectionDict[name].description), 331 self.__getShortDescription(sectionDict[name].description),
330 'Deprecated': 332 'Deprecated':
331 self.__checkDeprecated(sectionDict[name].description) and 333 self.__checkDeprecated(sectionDict[name].description) and
332 self.listEntryDeprecatedTemplate or "", 334 self.listEntryDeprecatedTemplate or "",
333 })) 335 }))
334 if kwSuffix: 336 n = ("{0} ({1})".format(name, kwSuffix) if kwSuffix
335 n = "{0} ({1})".format(name, kwSuffix) 337 else "{0}".format(name))
336 else:
337 n = "{0}".format(name)
338 self.keywords.append((n, "#{0}".format(name))) 338 self.keywords.append((n, "#{0}".format(name)))
339 return ''.join(lst) 339 return ''.join(lst)
340 340
341 def __genGlobalsListSection(self, class_=None): 341 def __genGlobalsListSection(self, class_=None):
342 """ 342 """
345 345
346 @param class_ reference to a class object (Class) 346 @param class_ reference to a class object (Class)
347 @return The globals list section. (string) 347 @return The globals list section. (string)
348 """ 348 """
349 attrNames = [] 349 attrNames = []
350 if class_ is not None: 350 scope = class_ if class_ is not None else self.module
351 scope = class_
352 else:
353 scope = self.module
354 attrNames = sorted(attr for attr in scope.globals.keys() 351 attrNames = sorted(attr for attr in scope.globals.keys()
355 if not scope.globals[attr].isSignal) 352 if not scope.globals[attr].isSignal)
356 if attrNames: 353 s = (
357 s = ''.join( 354 ''.join(
358 [self.listEntrySimpleTemplate.format(**{'Name': name}) 355 [self.listEntrySimpleTemplate.format(**{'Name': name})
359 for name in attrNames]) 356 for name in attrNames])
360 else: 357 if attrNames else
361 s = self.listEntryNoneTemplate 358 self.listEntryNoneTemplate
359 )
362 return self.listTemplate.format(**{'Entries': s}) 360 return self.listTemplate.format(**{'Entries': s})
363 361
364 def __genClassListSection(self): 362 def __genClassListSection(self):
365 """ 363 """
366 Private method to generate the section listing all classes of the 364 Private method to generate the section listing all classes of the
416 classNames = sorted(list(self.module.classes.keys())) 414 classNames = sorted(list(self.module.classes.keys()))
417 classes = [] 415 classes = []
418 for className in classNames: 416 for className in classNames:
419 _class = self.module.classes[className] 417 _class = self.module.classes[className]
420 supers = _class.super 418 supers = _class.super
421 if len(supers) > 0: 419 supers = ', '.join(supers) if len(supers) > 0 else "None"
422 supers = ', '.join(supers)
423 else:
424 supers = 'None'
425 420
426 globalsList = self.__genGlobalsListSection(_class) 421 globalsList = self.__genGlobalsListSection(_class)
427 classMethList, classMethBodies = self.__genMethodSection( 422 classMethList, classMethBodies = self.__genMethodSection(
428 _class, className, Function.Class) 423 _class, className, Function.Class)
429 methList, methBodies = self.__genMethodSection( 424 methList, methBodies = self.__genMethodSection(
472 (boolean) 467 (boolean)
473 @return methods list section (string) 468 @return methods list section (string)
474 """ 469 """
475 lst = [] 470 lst = []
476 if includeInit: 471 if includeInit:
477 try: 472 with contextlib.suppress(KeyError):
478 lst.append(self.listEntryTemplate.format( 473 lst.append(self.listEntryTemplate.format(
479 **{'Link': "{0}.{1}".format(className, '__init__'), 474 **{'Link': "{0}.{1}".format(className, '__init__'),
480 'Name': clsName, 475 'Name': clsName,
481 'Description': self.__getShortDescription( 476 'Description': self.__getShortDescription(
482 sectionDict['__init__'].description), 477 sectionDict['__init__'].description),
485 self.listEntryDeprecatedTemplate or "", 480 self.listEntryDeprecatedTemplate or "",
486 })) 481 }))
487 self.keywords.append( 482 self.keywords.append(
488 ("{0} (Constructor)".format(className), 483 ("{0} (Constructor)".format(className),
489 "#{0}.{1}".format(className, '__init__'))) 484 "#{0}.{1}".format(className, '__init__')))
490 except KeyError:
491 pass
492 485
493 for name in names: 486 for name in names:
494 lst.append(self.listEntryTemplate.format( 487 lst.append(self.listEntryTemplate.format(
495 **{'Link': "{0}.{1}".format(className, name), 488 **{'Link': "{0}.{1}".format(className, name),
496 'Name': sectionDict[name].name, 489 'Name': sectionDict[name].name,
631 classNames = sorted(list(obj.classes.keys())) 624 classNames = sorted(list(obj.classes.keys()))
632 classes = [] 625 classes = []
633 for className in classNames: 626 for className in classNames:
634 _class = obj.classes[className] 627 _class = obj.classes[className]
635 supers = _class.super 628 supers = _class.super
636 if len(supers) > 0: 629 supers = ', '.join(supers) if len(supers) > 0 else "None"
637 supers = ', '.join(supers)
638 else:
639 supers = 'None'
640 630
641 methList, methBodies = self.__genMethodSection( 631 methList, methBodies = self.__genMethodSection(
642 _class, className, Function.General) 632 _class, className, Function.General)
643 633
644 try: 634 try:
1165 else: 1155 else:
1166 lastItem.append(ditem) 1156 lastItem.append(ditem)
1167 elif not inTagSection: 1157 elif not inTagSection:
1168 lastItem.append(ditem) 1158 lastItem.append(ditem)
1169 1159
1170 if paragraphs: 1160 description = self.__genParagraphs(paragraphs) if paragraphs else ""
1171 description = self.__genParagraphs(paragraphs) 1161
1172 else: 1162 parameterSect = (
1173 description = "" 1163 self.parametersListTemplate.format(
1174
1175 if paramList:
1176 parameterSect = self.parametersListTemplate.format(
1177 **{'Parameters': self.__genParamDescriptionListSection( 1164 **{'Parameters': self.__genParamDescriptionListSection(
1178 paramList)}) 1165 paramList)})
1179 else: 1166 if paramList else
1180 parameterSect = "" 1167 ""
1181 1168 )
1182 if returns: 1169
1183 returnSect = self.returnsTemplate.format( 1170 returnSect = (
1171 self.returnsTemplate.format(
1184 html_uencode('\n'.join(returns))) 1172 html_uencode('\n'.join(returns)))
1185 else: 1173 if returns else
1186 returnSect = "" 1174 ""
1187 1175 )
1188 if returnTypes: 1176
1189 returnTypesSect = self.returnTypesTemplate.format( 1177 returnTypesSect = (
1178 self.returnTypesTemplate.format(
1190 html_uencode('\n'.join(returnTypes))) 1179 html_uencode('\n'.join(returnTypes)))
1191 else: 1180 if returnTypes else
1192 returnTypesSect = "" 1181 ""
1193 1182 )
1194 if yields: 1183
1195 yieldSect = self.yieldsTemplate.format( 1184 yieldSect = (
1185 self.yieldsTemplate.format(
1196 html_uencode('\n'.join(yields))) 1186 html_uencode('\n'.join(yields)))
1197 else: 1187 if yields else
1198 yieldSect = "" 1188 ""
1199 1189 )
1200 if yieldTypes: 1190
1201 yieldTypesSect = self.yieldTypesTemplate.format( 1191 yieldTypesSect = (
1192 self.yieldTypesTemplate.format(
1202 html_uencode('\n'.join(yieldTypes))) 1193 html_uencode('\n'.join(yieldTypes)))
1203 else: 1194 if yieldTypes else
1204 yieldTypesSect = "" 1195 ""
1205 1196 )
1206 if exceptionDict: 1197
1207 exceptionSect = self.exceptionsListTemplate.format( 1198 exceptionSect = (
1199 self.exceptionsListTemplate.format(
1208 **{'Exceptions': self.__genDescriptionListSection( 1200 **{'Exceptions': self.__genDescriptionListSection(
1209 exceptionDict, self.exceptionsListEntryTemplate)}) 1201 exceptionDict, self.exceptionsListEntryTemplate)})
1210 else: 1202 if exceptionDict else
1211 exceptionSect = "" 1203 ""
1212 1204 )
1213 if signalDict: 1205
1214 signalSect = self.signalsListTemplate.format( 1206 signalSect = (
1207 self.signalsListTemplate.format(
1215 **{'Signals': self.__genDescriptionListSection( 1208 **{'Signals': self.__genDescriptionListSection(
1216 signalDict, self.signalsListEntryTemplate)}) 1209 signalDict, self.signalsListEntryTemplate)})
1217 else: 1210 if signalDict else
1218 signalSect = "" 1211 ""
1219 1212 )
1220 if eventDict: 1213
1221 eventSect = self.eventsListTemplate.format( 1214 eventSect = (
1215 self.eventsListTemplate.format(
1222 **{'Events': self.__genDescriptionListSection( 1216 **{'Events': self.__genDescriptionListSection(
1223 eventDict, self.eventsListEntryTemplate)}) 1217 eventDict, self.eventsListEntryTemplate)})
1224 else: 1218 if eventDict else
1225 eventSect = "" 1219 ""
1226 1220 )
1227 if deprecated: 1221
1228 deprecatedSect = self.deprecatedTemplate.format( 1222 deprecatedSect = (
1223 self.deprecatedTemplate.format(
1229 **{'Lines': html_uencode('\n'.join(deprecated))}) 1224 **{'Lines': html_uencode('\n'.join(deprecated))})
1230 else: 1225 if deprecated else
1231 deprecatedSect = "" 1226 ""
1232 1227 )
1233 if authorInfo: 1228
1234 authorInfoSect = self.authorInfoTemplate.format( 1229 authorInfoSect = (
1230 self.authorInfoTemplate.format(
1235 **{'Authors': html_uencode('\n'.join(authorInfo))}) 1231 **{'Authors': html_uencode('\n'.join(authorInfo))})
1236 else: 1232 if authorInfo else
1237 authorInfoSect = "" 1233 ""
1238 1234 )
1239 if sinceInfo: 1235
1240 sinceInfoSect = self.sinceInfoTemplate.format( 1236 sinceInfoSect = (
1237 self.sinceInfoTemplate.format(
1241 **{'Info': html_uencode(sinceInfo[0])}) 1238 **{'Info': html_uencode(sinceInfo[0])})
1242 else: 1239 if sinceInfo else
1243 sinceInfoSect = "" 1240 ""
1244 1241 )
1245 if seeList: 1242
1246 seeSect = self.seeListTemplate.format( 1243 seeSect = (
1244 self.seeListTemplate.format(
1247 **{'Links': self.__genSeeListSection( 1245 **{'Links': self.__genSeeListSection(
1248 seeList, self.seeListEntryTemplate)}) 1246 seeList, self.seeListEntryTemplate)})
1249 else: 1247 if seeList else
1250 seeSect = '' 1248 ''
1249 )
1251 1250
1252 return "".join([ 1251 return "".join([
1253 deprecatedSect, description, parameterSect, returnSect, 1252 deprecatedSect, description, parameterSect, returnSect,
1254 returnTypesSect, yieldSect, yieldTypesSect, exceptionSect, 1253 returnTypesSect, yieldSect, yieldTypesSect, exceptionSect,
1255 signalSect, eventSect, authorInfoSect, seeSect, sinceInfoSect, 1254 signalSect, eventSect, authorInfoSect, seeSect, sinceInfoSect,

eric ide

mercurial