DocumentationTools/ModuleDocumentor.py

changeset 1227
c5db073a124f
parent 945
8cd4d08fa9f6
child 1229
a8207dc73672
equal deleted inserted replaced
1225:254ec677c775 1227:c5db073a124f
16 16
17 from . import TemplatesListsStyle 17 from . import TemplatesListsStyle
18 from . import TemplatesListsStyleCSS 18 from . import TemplatesListsStyleCSS
19 19
20 from Utilities import html_uencode 20 from Utilities import html_uencode
21 from Utilities.ModuleParser import RB_SOURCE 21 from Utilities.ModuleParser import RB_SOURCE, Function
22 22
23 _signal = re.compile(r""" 23 _signal = re.compile(r"""
24 ^@signal [ \t]+ 24 ^@signal [ \t]+
25 (?P<SignalName1> 25 (?P<SignalName1>
26 [a-zA-Z_] \w* [ \t]* \( [^)]* \) 26 [a-zA-Z_] \w* [ \t]* \( [^)]* \)
374 supers = ', '.join(supers) 374 supers = ', '.join(supers)
375 else: 375 else:
376 supers = 'None' 376 supers = 'None'
377 377
378 globalsList = self.__genGlobalsListSection(_class) 378 globalsList = self.__genGlobalsListSection(_class)
379 methList, methBodies = self.__genMethodSection(_class, className) 379 classMethList, classMethBodies = \
380 self.__genMethodSection(_class, className, Function.Class)
381 methList, methBodies = \
382 self.__genMethodSection(_class, className, Function.General)
383 staticMethList, staticMethBodies = \
384 self.__genMethodSection(_class, className, Function.Static)
380 385
381 try: 386 try:
382 clsBody = self.classTemplate.format(**{ \ 387 clsBody = self.classTemplate.format(**{ \
383 'Anchor': className, 388 'Anchor': className,
384 'Class': _class.name, 389 'Class': _class.name,
385 'ClassSuper': supers, 390 'ClassSuper': supers,
386 'ClassDescription': self.__formatDescription(_class.description), 391 'ClassDescription': self.__formatDescription(_class.description),
387 'GlobalsList': globalsList, 392 'GlobalsList': globalsList,
393 'ClassMethodList': classMethList,
388 'MethodList': methList, 394 'MethodList': methList,
389 'MethodDetails': methBodies, 395 'StaticMethodList': staticMethList,
396 'MethodDetails': classMethBodies + methBodies + staticMethBodies,
390 }) 397 })
391 except TagError as e: 398 except TagError as e:
392 sys.stderr.write("Error in tags of description of class {0}.\n".format( 399 sys.stderr.write("Error in tags of description of class {0}.\n".format(
393 className)) 400 className))
394 sys.stderr.write("{0}\n".format(e)) 401 sys.stderr.write("{0}\n".format(e))
396 403
397 classes.append(clsBody) 404 classes.append(clsBody)
398 405
399 return ''.join(classes) 406 return ''.join(classes)
400 407
401 def __genMethodsListSection(self, names, dict, className, clsName): 408 def __genMethodsListSection(self, names, dict, className, clsName,
409 includeInit=True):
402 """ 410 """
403 Private method to generate the methods list section of a class. 411 Private method to generate the methods list section of a class.
404 412
405 @param names The names to appear in the list. (list of strings) 413 @param names names to appear in the list (list of strings)
406 @param dict A dictionary containing all relevant information. 414 @param dict dictionary containing all relevant information
407 @param className The class name containing the names. 415 @param className class name containing the names
408 @param clsName The visible class name containing the names. 416 @param clsName visible class name containing the names
409 @return The list section. (string) 417 @param includeInit flag indicating to include the __init__ method (boolean)
418 @return methods list section (string)
410 """ 419 """
411 lst = [] 420 lst = []
412 try: 421 if includeInit:
413 lst.append(self.listEntryTemplate.format(**{ \ 422 try:
414 'Link': "{0}.{1}".format(className, '__init__'), 423 lst.append(self.listEntryTemplate.format(**{ \
415 'Name': clsName, 424 'Link': "{0}.{1}".format(className, '__init__'),
416 'Description': self.__getShortDescription(dict['__init__'].description), 425 'Name': clsName,
417 'Deprecated': self.__checkDeprecated(dict['__init__'].description) and \ 426 'Description': self.__getShortDescription(dict['__init__'].description),
418 self.listEntryDeprecatedTemplate or "", 427 'Deprecated': self.__checkDeprecated(dict['__init__'].description) and \
419 })) 428 self.listEntryDeprecatedTemplate or "",
420 self.keywords.append(("{0} (Constructor)".format(className), 429 }))
421 "#{0}.{1}".format(className, '__init__'))) 430 self.keywords.append(("{0} (Constructor)".format(className),
422 except KeyError: 431 "#{0}.{1}".format(className, '__init__')))
423 pass 432 except KeyError:
424 433 pass
434
425 for name in names: 435 for name in names:
426 lst.append(self.listEntryTemplate.format(**{ \ 436 lst.append(self.listEntryTemplate.format(**{ \
427 'Link': "{0}.{1}".format(className, name), 437 'Link': "{0}.{1}".format(className, name),
428 'Name': dict[name].name, 438 'Name': dict[name].name,
429 'Description': self.__getShortDescription(dict[name].description), 439 'Description': self.__getShortDescription(dict[name].description),
432 })) 442 }))
433 self.keywords.append(("{0}.{1}".format(className, name), 443 self.keywords.append(("{0}.{1}".format(className, name),
434 "#{0}.{1}".format(className, name))) 444 "#{0}.{1}".format(className, name)))
435 return ''.join(lst) 445 return ''.join(lst)
436 446
437 def __genMethodSection(self, obj, className): 447 def __genMethodSection(self, obj, className, filter):
438 """ 448 """
439 Private method to generate the method details section. 449 Private method to generate the method details section.
440 450
441 @param obj Reference to the object being formatted. 451 @param obj reference to the object being formatted
442 @param className Name of the class containing the method. (string) 452 @param className name of the class containing the method (string)
443 @return The method list and method details section. (tuple of two string) 453 @param filter filter value designating the method types
454 @return method list and method details section (tuple of two string)
444 """ 455 """
445 methList = [] 456 methList = []
446 methBodies = [] 457 methBodies = []
447 methods = sorted(list(obj.methods.keys())) 458 methods = sorted([k for k in obj.methods.keys()
459 if obj.methods[k].modifier == filter])
448 if '__init__' in methods: 460 if '__init__' in methods:
449 methods.remove('__init__') 461 methods.remove('__init__')
450 try: 462 try:
451 methBody = self.constructorTemplate.format(**{ \ 463 methBody = self.constructorTemplate.format(**{ \
452 'Anchor': className, 464 'Anchor': className,
461 "Error in tags of description of method {0}.{1}.\n".format( 473 "Error in tags of description of method {0}.{1}.\n".format(
462 className, '__init__')) 474 className, '__init__'))
463 sys.stderr.write("{0}\n".format(e)) 475 sys.stderr.write("{0}\n".format(e))
464 methBody = "" 476 methBody = ""
465 methBodies.append(methBody) 477 methBodies.append(methBody)
466 478
479 if filter == Function.Class:
480 methodClassifier = " (class method)"
481 elif filter == Function.Static:
482 methodClassifier = " (static)"
483 else:
484 methodClassifier = ""
467 for method in methods: 485 for method in methods:
468 try: 486 try:
469 methBody = self.methodTemplate.format(**{ \ 487 methBody = self.methodTemplate.format(**{ \
470 'Anchor': className, 488 'Anchor': className,
471 'Class': obj.name, 489 'Class': obj.name,
472 'Method': obj.methods[method].name, 490 'Method': obj.methods[method].name,
491 'MethodClassifier': methodClassifier,
473 'MethodDescription': \ 492 'MethodDescription': \
474 self.__formatDescription(obj.methods[method].description), 493 self.__formatDescription(obj.methods[method].description),
475 'Params': ', '.join(obj.methods[method].parameters[1:]), 494 'Params': ', '.join(obj.methods[method].parameters[1:]),
476 }) 495 })
477 except TagError as e: 496 except TagError as e:
480 className, method)) 499 className, method))
481 sys.stderr.write("{0}\n".format(e)) 500 sys.stderr.write("{0}\n".format(e))
482 methBody = "" 501 methBody = ""
483 methBodies.append(methBody) 502 methBodies.append(methBody)
484 503
485 methList = self.__genMethodsListSection(methods, obj.methods, className, obj.name) 504 methList = self.__genMethodsListSection(methods, obj.methods, className,
505 obj.name, includeInit='__init__' in methods)
486 506
487 if not methList: 507 if not methList:
488 methList = self.listEntryNoneTemplate 508 methList = self.listEntryNoneTemplate
489 return self.listTemplate.format(**{ \ 509 return self.listTemplate.format(**{ \
490 'Entries': methList, 510 'Entries': methList,
499 rbModulesNames = sorted(list(self.module.modules.keys())) 519 rbModulesNames = sorted(list(self.module.modules.keys()))
500 rbModules = [] 520 rbModules = []
501 for rbModuleName in rbModulesNames: 521 for rbModuleName in rbModulesNames:
502 rbModule = self.module.modules[rbModuleName] 522 rbModule = self.module.modules[rbModuleName]
503 globalsList = self.__genGlobalsListSection(rbModule) 523 globalsList = self.__genGlobalsListSection(rbModule)
504 methList, methBodies = self.__genMethodSection(rbModule, rbModuleName) 524 methList, methBodies = \
525 self.__genMethodSection(rbModule, rbModuleName, Function.General)
505 classList, classBodies = \ 526 classList, classBodies = \
506 self.__genRbModulesClassesSection(rbModule, rbModuleName) 527 self.__genRbModulesClassesSection(rbModule, rbModuleName)
507 528
508 try: 529 try:
509 rbmBody = self.rbModuleTemplate.format(**{ \ 530 rbmBody = self.rbModuleTemplate.format(**{ \
543 if len(supers) > 0: 564 if len(supers) > 0:
544 supers = ', '.join(supers) 565 supers = ', '.join(supers)
545 else: 566 else:
546 supers = 'None' 567 supers = 'None'
547 568
548 methList, methBodies = self.__genMethodSection(_class, className) 569 methList, methBodies = \
570 self.__genMethodSection(_class, className, Function.General)
549 571
550 try: 572 try:
551 clsBody = self.rbModulesClassTemplate.format(**{ \ 573 clsBody = self.rbModulesClassTemplate.format(**{ \
552 'Anchor': className, 574 'Anchor': className,
553 'Class': _class.name, 575 'Class': _class.name,

eric ide

mercurial