DocumentationTools/ModuleDocumentor.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
12 """ 12 """
13 13
14 import sys 14 import sys
15 import re 15 import re
16 16
17 import TemplatesListsStyle 17 from . import TemplatesListsStyle
18 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
22 22
23 _signal = re.compile(r""" 23 _signal = re.compile(r"""
232 self.__formatDescription(self.module.description), 232 self.__formatDescription(self.module.description),
233 'GlobalsList' : globalsList, 233 'GlobalsList' : globalsList,
234 'ClassList' : classList, 234 'ClassList' : classList,
235 'FunctionList' : functionList, 235 'FunctionList' : functionList,
236 } 236 }
237 except TagError, e: 237 except TagError as e:
238 sys.stderr.write("Error in tags of description of module %s.\n" % \ 238 sys.stderr.write("Error in tags of description of module %s.\n" % \
239 self.module.name) 239 self.module.name)
240 sys.stderr.write("%s\n" % e) 240 sys.stderr.write("%s\n" % e)
241 return "" 241 return ""
242 242
298 """ 298 """
299 Private method to generate the section listing all classes of the module. 299 Private method to generate the section listing all classes of the module.
300 300
301 @return The classes list section. (string) 301 @return The classes list section. (string)
302 """ 302 """
303 names = self.module.classes.keys() 303 names = sorted(list(self.module.classes.keys()))
304 names.sort()
305 if names: 304 if names:
306 self.empty = False 305 self.empty = False
307 s = self.__genListSection(names, self.module.classes) 306 s = self.__genListSection(names, self.module.classes)
308 else: 307 else:
309 s = self.listEntryNoneTemplate 308 s = self.listEntryNoneTemplate
316 Private method to generate the section listing all modules of the file 315 Private method to generate the section listing all modules of the file
317 (Ruby only). 316 (Ruby only).
318 317
319 @return The modules list section. (string) 318 @return The modules list section. (string)
320 """ 319 """
321 names = self.module.modules.keys() 320 names = sorted(list(self.module.modules.keys()))
322 names.sort()
323 if names: 321 if names:
324 self.empty = False 322 self.empty = False
325 s = self.__genListSection(names, self.module.modules) 323 s = self.__genListSection(names, self.module.modules)
326 else: 324 else:
327 s = self.listEntryNoneTemplate 325 s = self.listEntryNoneTemplate
333 """ 331 """
334 Private method to generate the section listing all functions of the module. 332 Private method to generate the section listing all functions of the module.
335 333
336 @return The functions list section. (string) 334 @return The functions list section. (string)
337 """ 335 """
338 names = self.module.functions.keys() 336 names = sorted(list(self.module.functions.keys()))
339 names.sort()
340 if names: 337 if names:
341 self.empty = False 338 self.empty = False
342 s = self.__genListSection(names, self.module.functions) 339 s = self.__genListSection(names, self.module.functions)
343 else: 340 else:
344 s = self.listEntryNoneTemplate 341 s = self.listEntryNoneTemplate
350 """ 347 """
351 Private method to generate the document section with details about classes. 348 Private method to generate the document section with details about classes.
352 349
353 @return The classes details section. (string) 350 @return The classes details section. (string)
354 """ 351 """
355 classNames = self.module.classes.keys() 352 classNames = sorted(list(self.module.classes.keys()))
356 classNames.sort()
357 classes = [] 353 classes = []
358 for className in classNames: 354 for className in classNames:
359 _class = self.module.classes[className] 355 _class = self.module.classes[className]
360 supers = _class.super 356 supers = _class.super
361 if len(supers) > 0: 357 if len(supers) > 0:
374 'ClassDescription' : self.__formatDescription(_class.description), 370 'ClassDescription' : self.__formatDescription(_class.description),
375 'GlobalsList' : globalsList, 371 'GlobalsList' : globalsList,
376 'MethodList' : methList, 372 'MethodList' : methList,
377 'MethodDetails' : methBodies, 373 'MethodDetails' : methBodies,
378 } 374 }
379 except TagError, e: 375 except TagError as e:
380 sys.stderr.write("Error in tags of description of class %s.\n" % \ 376 sys.stderr.write("Error in tags of description of class %s.\n" % \
381 className) 377 className)
382 sys.stderr.write("%s\n" % e) 378 sys.stderr.write("%s\n" % e)
383 clsBody = "" 379 clsBody = ""
384 380
430 @param className Name of the class containing the method. (string) 426 @param className Name of the class containing the method. (string)
431 @return The method list and method details section. (tuple of two string) 427 @return The method list and method details section. (tuple of two string)
432 """ 428 """
433 methList = [] 429 methList = []
434 methBodies = [] 430 methBodies = []
435 methods = obj.methods.keys() 431 methods = sorted(list(obj.methods.keys()))
436 methods.sort()
437
438 # first do the constructor
439 if '__init__' in methods: 432 if '__init__' in methods:
440 methods.remove('__init__') 433 methods.remove('__init__')
441 try: 434 try:
442 methBody = self.constructorTemplate % { \ 435 methBody = self.constructorTemplate % { \
443 'Anchor' : className, 436 'Anchor' : className,
445 'Method' : '__init__', 438 'Method' : '__init__',
446 'MethodDescription' : \ 439 'MethodDescription' : \
447 self.__formatDescription(obj.methods['__init__'].description), 440 self.__formatDescription(obj.methods['__init__'].description),
448 'Params' : ', '.join(obj.methods['__init__'].parameters[1:]), 441 'Params' : ', '.join(obj.methods['__init__'].parameters[1:]),
449 } 442 }
450 except TagError, e: 443 except TagError as e:
451 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ 444 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \
452 (className, '__init__')) 445 (className, '__init__'))
453 sys.stderr.write("%s\n" % e) 446 sys.stderr.write("%s\n" % e)
454 methBody = "" 447 methBody = ""
455 methBodies.append(methBody) 448 methBodies.append(methBody)
462 'Method' : obj.methods[method].name, 455 'Method' : obj.methods[method].name,
463 'MethodDescription' : \ 456 'MethodDescription' : \
464 self.__formatDescription(obj.methods[method].description), 457 self.__formatDescription(obj.methods[method].description),
465 'Params' : ', '.join(obj.methods[method].parameters[1:]), 458 'Params' : ', '.join(obj.methods[method].parameters[1:]),
466 } 459 }
467 except TagError, e: 460 except TagError as e:
468 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ 461 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \
469 (className, method)) 462 (className, method))
470 sys.stderr.write("%s\n" % e) 463 sys.stderr.write("%s\n" % e)
471 methBody = "" 464 methBody = ""
472 methBodies.append(methBody) 465 methBodies.append(methBody)
483 """ 476 """
484 Private method to generate the document section with details about Ruby modules. 477 Private method to generate the document section with details about Ruby modules.
485 478
486 @return The Ruby modules details section. (string) 479 @return The Ruby modules details section. (string)
487 """ 480 """
488 rbModulesNames = self.module.modules.keys() 481 rbModulesNames = sorted(list(self.module.modules.keys()))
489 rbModulesNames.sort()
490 rbModules = [] 482 rbModules = []
491 for rbModuleName in rbModulesNames: 483 for rbModuleName in rbModulesNames:
492 rbModule = self.module.modules[rbModuleName] 484 rbModule = self.module.modules[rbModuleName]
493 globalsList = self.__genGlobalsListSection(rbModule) 485 globalsList = self.__genGlobalsListSection(rbModule)
494 methList, methBodies = self.__genMethodSection(rbModule, rbModuleName) 486 methList, methBodies = self.__genMethodSection(rbModule, rbModuleName)
504 'ClassesList' : classList, 496 'ClassesList' : classList,
505 'ClassesDetails' : classBodies, 497 'ClassesDetails' : classBodies,
506 'FunctionsList' : methList, 498 'FunctionsList' : methList,
507 'FunctionsDetails' : methBodies, 499 'FunctionsDetails' : methBodies,
508 } 500 }
509 except TagError, e: 501 except TagError as e:
510 sys.stderr.write("Error in tags of description of Ruby module %s.\n" % \ 502 sys.stderr.write("Error in tags of description of Ruby module %s.\n" % \
511 rbModuleName) 503 rbModuleName)
512 sys.stderr.write("%s\n" % e) 504 sys.stderr.write("%s\n" % e)
513 rbmBody = "" 505 rbmBody = ""
514 506
522 514
523 @param obj Reference to the object being formatted. 515 @param obj Reference to the object being formatted.
524 @param modName Name of the Ruby module containing the classes. (string) 516 @param modName Name of the Ruby module containing the classes. (string)
525 @return The classes list and classes details section. (tuple of two string) 517 @return The classes list and classes details section. (tuple of two string)
526 """ 518 """
527 classNames = obj.classes.keys() 519 classNames = sorted(list(obj.classes.keys()))
528 classNames.sort()
529 classes = [] 520 classes = []
530 for className in classNames: 521 for className in classNames:
531 _class = obj.classes[className] 522 _class = obj.classes[className]
532 supers = _class.super 523 supers = _class.super
533 if len(supers) > 0: 524 if len(supers) > 0:
545 'ClassSuper' : supers, 536 'ClassSuper' : supers,
546 'ClassDescription' : self.__formatDescription(_class.description), 537 'ClassDescription' : self.__formatDescription(_class.description),
547 'MethodList' : methList, 538 'MethodList' : methList,
548 'MethodDetails' : methBodies, 539 'MethodDetails' : methBodies,
549 } 540 }
550 except TagError, e: 541 except TagError as e:
551 sys.stderr.write("Error in tags of description of class %s.\n" % \ 542 sys.stderr.write("Error in tags of description of class %s.\n" % \
552 className) 543 className)
553 sys.stderr.write("%s\n" % e) 544 sys.stderr.write("%s\n" % e)
554 clsBody = "" 545 clsBody = ""
555 546
592 Private method to generate the document section with details about functions. 583 Private method to generate the document section with details about functions.
593 584
594 @return The functions details section. (string) 585 @return The functions details section. (string)
595 """ 586 """
596 funcBodies = [] 587 funcBodies = []
597 funcNames = self.module.functions.keys() 588 funcNames = sorted(list(self.module.functions.keys()))
598 funcNames.sort()
599 for funcName in funcNames: 589 for funcName in funcNames:
600 try: 590 try:
601 funcBody = self.functionTemplate % { \ 591 funcBody = self.functionTemplate % { \
602 'Anchor' : funcName, 592 'Anchor' : funcName,
603 'Function' : self.module.functions[funcName].name, 593 'Function' : self.module.functions[funcName].name,
604 'FunctionDescription' : self.__formatDescription(\ 594 'FunctionDescription' : self.__formatDescription(\
605 self.module.functions[funcName].description), 595 self.module.functions[funcName].description),
606 'Params' : ', '.join(self.module.functions[funcName].parameters), 596 'Params' : ', '.join(self.module.functions[funcName].parameters),
607 } 597 }
608 except TagError, e: 598 except TagError as e:
609 sys.stderr.write("Error in tags of description of function %s.\n" % \ 599 sys.stderr.write("Error in tags of description of function %s.\n" % \
610 funcName) 600 funcName)
611 sys.stderr.write("%s\n" % e) 601 sys.stderr.write("%s\n" % e)
612 funcBody = "" 602 funcBody = ""
613 603
707 list section. 697 list section.
708 @param template The template to be used for the list. (string) 698 @param template The template to be used for the list. (string)
709 @return The list section. (string) 699 @return The list section. (string)
710 """ 700 """
711 lst = [] 701 lst = []
712 keys = dictionary.keys() 702 keys = sorted(list(dictionary.keys()))
713 keys.sort()
714 for key in keys: 703 for key in keys:
715 lst.append(template % { \ 704 lst.append(template % { \
716 'Name' : key, 705 'Name' : key,
717 'Description' : html_uencode('\n'.join(dictionary[key])), 706 'Description' : html_uencode('\n'.join(dictionary[key])),
718 }) 707 })
793 """ 782 """
794 start = desc.find('{@') 783 start = desc.find('{@')
795 while start != -1: 784 while start != -1:
796 stop = desc.find('}', start + 2) 785 stop = desc.find('}', start + 2)
797 if stop == -1: 786 if stop == -1:
798 raise TagError, "Unterminated inline tag.\n%s" % desc 787 raise TagError("Unterminated inline tag.\n%s" % desc)
799 788
800 tagText = desc[start + 1:stop] 789 tagText = desc[start + 1:stop]
801 if tagText.startswith('@link'): 790 if tagText.startswith('@link'):
802 parts = tagText.split(None, 1) 791 parts = tagText.split(None, 1)
803 if len(parts) < 2: 792 if len(parts) < 2:
804 raise TagError, "Wrong format in inline tag %s.\n%s" % \ 793 raise TagError("Wrong format in inline tag %s.\n%s" % \
805 (parts[0], desc) 794 (parts[0], desc))
806 795
807 formattedTag = self.__formatCrossReferenceEntry(parts[1]) 796 formattedTag = self.__formatCrossReferenceEntry(parts[1])
808 desc = desc.replace("{%s}" % tagText, formattedTag) 797 desc = desc.replace("{%s}" % tagText, formattedTag)
809 else: 798 else:
810 tag = tagText.split(None, 1)[0] 799 tag = tagText.split(None, 1)[0]
811 raise TagError, "Unknown inline tag encountered, %s.\n%s" % \ 800 raise TagError("Unknown inline tag encountered, %s.\n%s" % \
812 (tag, desc) 801 (tag, desc))
813 802
814 start = desc.find('{@') 803 start = desc.find('{@')
815 804
816 return desc 805 return desc
817 806
849 if desc: 838 if desc:
850 if desc.startswith("@param") or desc.startswith("@keyparam"): 839 if desc.startswith("@param") or desc.startswith("@keyparam"):
851 inTagSection = True 840 inTagSection = True
852 parts = desc.split(None, 2) 841 parts = desc.split(None, 2)
853 if len(parts) < 2: 842 if len(parts) < 2:
854 raise TagError, "Wrong format in %s line.\n" % parts[0] 843 raise TagError("Wrong format in %s line.\n" % parts[0])
855 paramName = parts[1] 844 paramName = parts[1]
856 if parts[0] == "@keyparam": 845 if parts[0] == "@keyparam":
857 paramName += '=' 846 paramName += '='
858 try: 847 try:
859 paramList.append([paramName, [parts[2]]]) 848 paramList.append([paramName, [parts[2]]])
862 lastItem = paramList[-1][1] 851 lastItem = paramList[-1][1]
863 elif desc.startswith("@return"): 852 elif desc.startswith("@return"):
864 inTagSection = True 853 inTagSection = True
865 parts = desc.split(None, 1) 854 parts = desc.split(None, 1)
866 if len(parts) < 2: 855 if len(parts) < 2:
867 raise TagError, "Wrong format in %s line.\n" % parts[0] 856 raise TagError("Wrong format in %s line.\n" % parts[0])
868 returns = [parts[1]] 857 returns = [parts[1]]
869 lastItem = returns 858 lastItem = returns
870 elif desc.startswith("@exception") or \ 859 elif desc.startswith("@exception") or \
871 desc.startswith("@throws") or \ 860 desc.startswith("@throws") or \
872 desc.startswith("@raise"): 861 desc.startswith("@raise"):
873 inTagSection = True 862 inTagSection = True
874 parts = desc.split(None, 2) 863 parts = desc.split(None, 2)
875 if len(parts) < 2: 864 if len(parts) < 2:
876 raise TagError, "Wrong format in %s line.\n" % parts[0] 865 raise TagError("Wrong format in %s line.\n" % parts[0])
877 excName = parts[1] 866 excName = parts[1]
878 try: 867 try:
879 exceptionDict[excName] = [parts[2]] 868 exceptionDict[excName] = [parts[2]]
880 except IndexError: 869 except IndexError:
881 exceptionDict[excName] = [] 870 exceptionDict[excName] = []
882 lastItem = exceptionDict[excName] 871 lastItem = exceptionDict[excName]
883 elif desc.startswith("@signal"): 872 elif desc.startswith("@signal"):
884 inTagSection = True 873 inTagSection = True
885 m = _signal(desc,0) 874 m = _signal(desc,0)
886 if m is None: 875 if m is None:
887 raise TagError, "Wrong format in %s line.\n" % parts[0] 876 raise TagError("Wrong format in %s line.\n" % parts[0])
888 signalName = 1 and m.group("SignalName1") \ 877 signalName = 1 and m.group("SignalName1") \
889 or m.group("SignalName2") 878 or m.group("SignalName2")
890 signalDesc = 1 and m.group("SignalDescription1") \ 879 signalDesc = 1 and m.group("SignalDescription1") \
891 or m.group("SignalDescription2") 880 or m.group("SignalDescription2")
892 signalDict[signalName] = [] 881 signalDict[signalName] = []
895 lastItem = signalDict[signalName] 884 lastItem = signalDict[signalName]
896 elif desc.startswith("@event"): 885 elif desc.startswith("@event"):
897 inTagSection = True 886 inTagSection = True
898 m = _event(desc,0) 887 m = _event(desc,0)
899 if m is None: 888 if m is None:
900 raise TagError, "Wrong format in %s line.\n" % parts[0] 889 raise TagError("Wrong format in %s line.\n" % parts[0])
901 eventName = 1 and m.group("EventName1") \ 890 eventName = 1 and m.group("EventName1") \
902 or m.group("EventName2") 891 or m.group("EventName2")
903 eventDesc = 1 and m.group("EventDescription1") \ 892 eventDesc = 1 and m.group("EventDescription1") \
904 or m.group("EventDescription2") 893 or m.group("EventDescription2")
905 eventDict[eventName] = [] 894 eventDict[eventName] = []
908 lastItem = eventDict[eventName] 897 lastItem = eventDict[eventName]
909 elif desc.startswith("@deprecated"): 898 elif desc.startswith("@deprecated"):
910 inTagSection = True 899 inTagSection = True
911 parts = desc.split(None, 1) 900 parts = desc.split(None, 1)
912 if len(parts) < 2: 901 if len(parts) < 2:
913 raise TagError, "Wrong format in %s line.\n" % parts[0] 902 raise TagError("Wrong format in %s line.\n" % parts[0])
914 deprecated = [parts[1]] 903 deprecated = [parts[1]]
915 lastItem = deprecated 904 lastItem = deprecated
916 elif desc.startswith("@author"): 905 elif desc.startswith("@author"):
917 inTagSection = True 906 inTagSection = True
918 parts = desc.split(None, 1) 907 parts = desc.split(None, 1)
919 if len(parts) < 2: 908 if len(parts) < 2:
920 raise TagError, "Wrong format in %s line.\n" % parts[0] 909 raise TagError("Wrong format in %s line.\n" % parts[0])
921 authorInfo = [parts[1]] 910 authorInfo = [parts[1]]
922 lastItem = authorInfo 911 lastItem = authorInfo
923 elif desc.startswith("@since"): 912 elif desc.startswith("@since"):
924 inTagSection = True 913 inTagSection = True
925 parts = desc.split(None, 1) 914 parts = desc.split(None, 1)
926 if len(parts) < 2: 915 if len(parts) < 2:
927 raise TagError, "Wrong format in %s line.\n" % parts[0] 916 raise TagError("Wrong format in %s line.\n" % parts[0])
928 sinceInfo = [parts[1]] 917 sinceInfo = [parts[1]]
929 lastItem = sinceInfo 918 lastItem = sinceInfo
930 elif desc.startswith("@see"): 919 elif desc.startswith("@see"):
931 inTagSection = True 920 inTagSection = True
932 parts = desc.split(None, 1) 921 parts = desc.split(None, 1)
933 if len(parts) < 2: 922 if len(parts) < 2:
934 raise TagError, "Wrong format in %s line.\n" % parts[0] 923 raise TagError("Wrong format in %s line.\n" % parts[0])
935 seeList.append([parts[1]]) 924 seeList.append([parts[1]])
936 lastItem = seeList[-1] 925 lastItem = seeList[-1]
937 elif desc.startswith("@@"): 926 elif desc.startswith("@@"):
938 lastItem.append(desc[1:]) 927 lastItem.append(desc[1:])
939 elif desc.startswith("@"): 928 elif desc.startswith("@"):
940 tag = desc.split(None, 1)[0] 929 tag = desc.split(None, 1)[0]
941 raise TagError, "Unknown tag encountered, %s.\n" % tag 930 raise TagError("Unknown tag encountered, %s.\n" % tag)
942 else: 931 else:
943 lastItem.append(ditem) 932 lastItem.append(ditem)
944 elif not inTagSection: 933 elif not inTagSection:
945 lastItem.append(ditem) 934 lastItem.append(ditem)
946 935

eric ide

mercurial