86 def isEmpty(self): |
86 def isEmpty(self): |
87 """ |
87 """ |
88 Public method to determine, if the module contains any classes or |
88 Public method to determine, if the module contains any classes or |
89 functions. |
89 functions. |
90 |
90 |
91 @return Flag indicating an empty module (i.e. __init__.py without |
91 @return flag indicating an empty module (i.e. __init__.py without |
92 any contents) |
92 any contents) |
|
93 @rtype bool |
93 """ |
94 """ |
94 return self.empty |
95 return self.empty |
95 |
96 |
96 def name(self): |
97 def name(self): |
97 """ |
98 """ |
98 Public method used to get the module name. |
99 Public method used to get the module name. |
99 |
100 |
100 @return The name of the module. (string) |
101 @return name of the module |
|
102 @rtype str |
101 """ |
103 """ |
102 return self.module.name |
104 return self.module.name |
103 |
105 |
104 def description(self): |
106 def description(self): |
105 """ |
107 """ |
106 Public method used to get the description of the module. |
108 Public method used to get the description of the module. |
107 |
109 |
108 @return The description of the module. (string) |
110 @return description of the module |
|
111 @rtype str |
109 """ |
112 """ |
110 return self.__formatDescription(self.module.description) |
113 return self.__formatDescription(self.module.description) |
111 |
114 |
112 def shortDescription(self): |
115 def shortDescription(self): |
113 """ |
116 """ |
114 Public method used to get the short description of the module. |
117 Public method used to get the short description of the module. |
115 |
118 |
116 The short description is just the first line of the modules |
119 The short description is just the first line of the modules |
117 description. |
120 description. |
118 |
121 |
119 @return The short description of the module. (string) |
122 @return short description of the module |
|
123 @rtype str |
120 """ |
124 """ |
121 return self.__getShortDescription(self.module.description) |
125 return self.__getShortDescription(self.module.description) |
122 |
126 |
123 def genDocument(self): |
127 def genDocument(self): |
124 """ |
128 """ |
125 Public method to generate the source code documentation. |
129 Public method to generate the source code documentation. |
126 |
130 |
127 @return The source code documentation. (string) |
131 @return source code documentation |
|
132 @rtype str |
128 """ |
133 """ |
129 doc = ( |
134 doc = ( |
130 TemplatesListsStyleCSS.headerTemplate.format(**{"Title": self.module.name}) |
135 TemplatesListsStyleCSS.headerTemplate.format(**{"Title": self.module.name}) |
131 + self.__genModuleSection() |
136 + self.__genModuleSection() |
132 + TemplatesListsStyleCSS.footerTemplate |
137 + TemplatesListsStyleCSS.footerTemplate |
136 |
141 |
137 def __genModuleSection(self): |
142 def __genModuleSection(self): |
138 """ |
143 """ |
139 Private method to generate the body of the document. |
144 Private method to generate the body of the document. |
140 |
145 |
141 @return The body of the document. (string) |
146 @return body of the document |
|
147 @rtype str |
142 """ |
148 """ |
143 globalsList = self.__genGlobalsListSection() |
149 globalsList = self.__genGlobalsListSection() |
144 classList = self.__genClassListSection() |
150 classList = self.__genClassListSection() |
145 functionList = self.__genFunctionListSection() |
151 functionList = self.__genFunctionListSection() |
146 try: |
152 try: |
189 |
195 |
190 def __genListSection(self, names, sectionDict, kwSuffix=""): |
196 def __genListSection(self, names, sectionDict, kwSuffix=""): |
191 """ |
197 """ |
192 Private method to generate a list section of the document. |
198 Private method to generate a list section of the document. |
193 |
199 |
194 @param names The names to appear in the list. (list of strings) |
200 @param names names to appear in the list |
|
201 @type list of str |
195 @param sectionDict dictionary containing all relevant information |
202 @param sectionDict dictionary containing all relevant information |
196 (dict) |
203 @type dict |
197 @param kwSuffix suffix to be used for the QtHelp keywords (string) |
204 @param kwSuffix suffix to be used for the QtHelp keywords |
198 @return list section (string) |
205 @type str |
|
206 @return list section |
|
207 @rtype str |
199 """ |
208 """ |
200 lst = [] |
209 lst = [] |
201 for name in names: |
210 for name in names: |
202 lst.append( |
211 lst.append( |
203 TemplatesListsStyleCSS.listEntryTemplate.format( |
212 TemplatesListsStyleCSS.listEntryTemplate.format( |
222 def __genGlobalsListSection(self, class_=None): |
231 def __genGlobalsListSection(self, class_=None): |
223 """ |
232 """ |
224 Private method to generate the section listing all global attributes of |
233 Private method to generate the section listing all global attributes of |
225 the module. |
234 the module. |
226 |
235 |
227 @param class_ reference to a class object (Class) |
236 @param class_ reference to a class object |
228 @return The globals list section. (string) |
237 @type class |
|
238 @return globals list section |
|
239 @rtype str |
229 """ |
240 """ |
230 attrNames = [] |
241 attrNames = [] |
231 scope = class_ if class_ is not None else self.module |
242 scope = class_ if class_ is not None else self.module |
232 attrNames = sorted( |
243 attrNames = sorted( |
233 attr for attr in scope.globals if not scope.globals[attr].isSignal |
244 attr for attr in scope.globals if not scope.globals[attr].isSignal |
249 def __genClassListSection(self): |
260 def __genClassListSection(self): |
250 """ |
261 """ |
251 Private method to generate the section listing all classes of the |
262 Private method to generate the section listing all classes of the |
252 module. |
263 module. |
253 |
264 |
254 @return The classes list section. (string) |
265 @return classes list section |
|
266 @rtype str |
255 """ |
267 """ |
256 names = sorted(self.module.classes) |
268 names = sorted(self.module.classes) |
257 if names: |
269 if names: |
258 self.empty = False |
270 self.empty = False |
259 s = self.__genListSection(names, self.module.classes) |
271 s = self.__genListSection(names, self.module.classes) |
264 def __genRbModulesListSection(self): |
276 def __genRbModulesListSection(self): |
265 """ |
277 """ |
266 Private method to generate the section listing all modules of the file |
278 Private method to generate the section listing all modules of the file |
267 (Ruby only). |
279 (Ruby only). |
268 |
280 |
269 @return The modules list section. (string) |
281 @return modules list section |
|
282 @rtype str |
270 """ |
283 """ |
271 names = sorted(self.module.modules) |
284 names = sorted(self.module.modules) |
272 if names: |
285 if names: |
273 self.empty = False |
286 self.empty = False |
274 s = self.__genListSection(names, self.module.modules) |
287 s = self.__genListSection(names, self.module.modules) |
279 def __genFunctionListSection(self): |
292 def __genFunctionListSection(self): |
280 """ |
293 """ |
281 Private method to generate the section listing all functions of the |
294 Private method to generate the section listing all functions of the |
282 module. |
295 module. |
283 |
296 |
284 @return The functions list section. (string) |
297 @return functions list section |
|
298 @rtype str |
285 """ |
299 """ |
286 names = sorted(self.module.functions) |
300 names = sorted(self.module.functions) |
287 if names: |
301 if names: |
288 self.empty = False |
302 self.empty = False |
289 s = self.__genListSection(names, self.module.functions) |
303 s = self.__genListSection(names, self.module.functions) |
294 def __genClassesSection(self): |
308 def __genClassesSection(self): |
295 """ |
309 """ |
296 Private method to generate the document section with details about |
310 Private method to generate the document section with details about |
297 classes. |
311 classes. |
298 |
312 |
299 @return The classes details section. (string) |
313 @return classes details section |
|
314 @rtype str |
300 """ |
315 """ |
301 classNames = sorted(self.module.classes) |
316 classNames = sorted(self.module.classes) |
302 classes = [] |
317 classes = [] |
303 for className in classNames: |
318 for className in classNames: |
304 _class = self.module.classes[className] |
319 _class = self.module.classes[className] |
350 self, names, sectionDict, className, clsName, includeInit=True |
365 self, names, sectionDict, className, clsName, includeInit=True |
351 ): |
366 ): |
352 """ |
367 """ |
353 Private method to generate the methods list section of a class. |
368 Private method to generate the methods list section of a class. |
354 |
369 |
355 @param names names to appear in the list (list of strings) |
370 @param names names to appear in the list |
|
371 @type list of str |
356 @param sectionDict dictionary containing all relevant information |
372 @param sectionDict dictionary containing all relevant information |
357 (dict) |
373 @type dict |
358 @param className class name containing the names |
374 @param className class name containing the names |
|
375 @type str |
359 @param clsName visible class name containing the names |
376 @param clsName visible class name containing the names |
|
377 @type str |
360 @param includeInit flag indicating to include the __init__ method |
378 @param includeInit flag indicating to include the __init__ method |
361 (boolean) |
379 @type bool |
362 @return methods list section (string) |
380 @return methods list section |
|
381 @rtype str |
363 """ |
382 """ |
364 lst = [] |
383 lst = [] |
365 if includeInit: |
384 if includeInit: |
366 with contextlib.suppress(KeyError): |
385 with contextlib.suppress(KeyError): |
367 lst.append( |
386 lst.append( |
412 def __genMethodSection(self, obj, className, modifierFilter): |
431 def __genMethodSection(self, obj, className, modifierFilter): |
413 """ |
432 """ |
414 Private method to generate the method details section. |
433 Private method to generate the method details section. |
415 |
434 |
416 @param obj reference to the object being formatted |
435 @param obj reference to the object being formatted |
417 @param className name of the class containing the method (string) |
436 @type class |
|
437 @param className name of the class containing the method |
|
438 @type str |
418 @param modifierFilter filter value designating the method types |
439 @param modifierFilter filter value designating the method types |
419 @return method list and method details section (tuple of two string) |
440 @type str |
|
441 @return method list and method details section |
|
442 @rtype tuple of (str, str) |
420 """ |
443 """ |
421 methList = [] |
444 methList = [] |
422 methBodies = [] |
445 methBodies = [] |
423 methods = sorted( |
446 methods = sorted( |
424 k for k in obj.methods if obj.methods[k].modifier == modifierFilter |
447 k for k in obj.methods if obj.methods[k].modifier == modifierFilter |
497 def __genRbModulesSection(self): |
520 def __genRbModulesSection(self): |
498 """ |
521 """ |
499 Private method to generate the document section with details about |
522 Private method to generate the document section with details about |
500 Ruby modules. |
523 Ruby modules. |
501 |
524 |
502 @return The Ruby modules details section. (string) |
525 @return Ruby modules details section |
|
526 @rtype str |
503 """ |
527 """ |
504 rbModulesNames = sorted(self.module.modules) |
528 rbModulesNames = sorted(self.module.modules) |
505 rbModules = [] |
529 rbModules = [] |
506 for rbModuleName in rbModulesNames: |
530 for rbModuleName in rbModulesNames: |
507 rbModule = self.module.modules[rbModuleName] |
531 rbModule = self.module.modules[rbModuleName] |
544 |
568 |
545 def __genRbModulesClassesSection(self, obj, modName): |
569 def __genRbModulesClassesSection(self, obj, modName): |
546 """ |
570 """ |
547 Private method to generate the Ruby module classes details section. |
571 Private method to generate the Ruby module classes details section. |
548 |
572 |
549 @param obj Reference to the object being formatted. |
573 @param obj reference to the object being formatted |
550 @param modName Name of the Ruby module containing the classes. (string) |
574 @type class |
551 @return The classes list and classes details section. |
575 @param modName name of the Ruby module containing the classes |
552 (tuple of two string) |
576 @type str |
|
577 @return classes list and classes details section |
|
578 @rtype tuple of (str, str) |
553 """ |
579 """ |
554 classNames = sorted(obj.classes) |
580 classNames = sorted(obj.classes) |
555 classes = [] |
581 classes = [] |
556 for className in classNames: |
582 for className in classNames: |
557 _class = obj.classes[className] |
583 _class = obj.classes[className] |
598 |
624 |
599 def __genRbModulesClassesListSection(self, names, sectionDict, moduleName): |
625 def __genRbModulesClassesListSection(self, names, sectionDict, moduleName): |
600 """ |
626 """ |
601 Private method to generate the classes list section of a Ruby module. |
627 Private method to generate the classes list section of a Ruby module. |
602 |
628 |
603 @param names The names to appear in the list. (list of strings) |
629 @param names names to appear in the list |
|
630 @type list of str |
604 @param sectionDict dictionary containing all relevant information |
631 @param sectionDict dictionary containing all relevant information |
605 (dict) |
632 @type dict |
606 @param moduleName name of the Ruby module containing the classes |
633 @param moduleName name of the Ruby module containing the classes |
607 (string) |
634 @type str |
608 @return The list section. (string) |
635 @return list section |
|
636 @rtype str |
609 """ |
637 """ |
610 lst = [] |
638 lst = [] |
611 for name in names: |
639 for name in names: |
612 lst.append( |
640 lst.append( |
613 TemplatesListsStyleCSS.listEntryTemplate.format( |
641 TemplatesListsStyleCSS.listEntryTemplate.format( |
636 def __genFunctionsSection(self): |
664 def __genFunctionsSection(self): |
637 """ |
665 """ |
638 Private method to generate the document section with details about |
666 Private method to generate the document section with details about |
639 functions. |
667 functions. |
640 |
668 |
641 @return The functions details section. (string) |
669 @return functions details section |
|
670 @rtype str |
642 """ |
671 """ |
643 funcBodies = [] |
672 funcBodies = [] |
644 funcNames = sorted(self.module.functions) |
673 funcNames = sorted(self.module.functions) |
645 for funcName in funcNames: |
674 for funcName in funcNames: |
646 try: |
675 try: |
671 Private method to determine the short description of an object. |
700 Private method to determine the short description of an object. |
672 |
701 |
673 The short description is just the first non empty line of the |
702 The short description is just the first non empty line of the |
674 documentation string. |
703 documentation string. |
675 |
704 |
676 @param desc The documentation string. (string) |
705 @param desc documentation string |
677 @return The short description. (string) |
706 @type str |
|
707 @return short description |
|
708 @rtype str |
678 """ |
709 """ |
679 dlist = desc.splitlines() |
710 dlist = desc.splitlines() |
680 sdlist = [] |
711 sdlist = [] |
681 descfound = 0 |
712 descfound = 0 |
682 for desc in dlist: |
713 for desc in dlist: |
709 def __checkDeprecated(self, descr): |
740 def __checkDeprecated(self, descr): |
710 """ |
741 """ |
711 Private method to check, if the object to be documented contains a |
742 Private method to check, if the object to be documented contains a |
712 deprecated flag. |
743 deprecated flag. |
713 |
744 |
714 @param descr documentation string (string) |
745 @param descr documentation string |
715 @return flag indicating the deprecation status (boolean) |
746 @type str |
|
747 @return flag indicating the deprecation status |
|
748 @rtype bool |
716 """ |
749 """ |
717 dlist = descr.splitlines() |
750 dlist = descr.splitlines() |
718 for desc in dlist: |
751 for desc in dlist: |
719 desc = desc.strip() |
752 desc = desc.strip() |
720 if desc.startswith("@deprecated"): |
753 if desc.startswith("@deprecated"): |
757 |
792 |
758 def __genDescriptionListSection(self, dictionary, template): |
793 def __genDescriptionListSection(self, dictionary, template): |
759 """ |
794 """ |
760 Private method to generate the list section of a description. |
795 Private method to generate the list section of a description. |
761 |
796 |
762 @param dictionary Dictionary containing the info for the |
797 @param dictionary dictionary containing the info for the |
763 list section. |
798 list section |
764 @param template The template to be used for the list. (string) |
799 @type dict |
765 @return The list section. (string) |
800 @param template template to be used for the list |
|
801 @type str |
|
802 @return list section |
|
803 @rtype str |
766 """ |
804 """ |
767 lst = [] |
805 lst = [] |
768 keys = sorted(dictionary) |
806 keys = sorted(dictionary) |
769 for key in keys: |
807 for key in keys: |
770 lst.append( |
808 lst.append( |
780 def __genParamDescriptionListSection(self, _list): |
818 def __genParamDescriptionListSection(self, _list): |
781 """ |
819 """ |
782 Private method to generate the list section of a description. |
820 Private method to generate the list section of a description. |
783 |
821 |
784 @param _list list containing the info for the parameter description |
822 @param _list list containing the info for the parameter description |
785 list section (list of lists with three elements) |
823 list section |
786 @return formatted list section (string) |
824 @type list of lists with three elements |
|
825 @return formatted list section |
|
826 @rtype str |
787 """ |
827 """ |
788 lst = [] |
828 lst = [] |
789 for name, type_, lines in _list: |
829 for name, type_, lines in _list: |
790 if type_: |
830 if type_: |
791 lst.append( |
831 lst.append( |
812 """ |
852 """ |
813 Private method to format a cross reference entry. |
853 Private method to format a cross reference entry. |
814 |
854 |
815 This cross reference entry looks like "package.module#member label". |
855 This cross reference entry looks like "package.module#member label". |
816 |
856 |
817 @param entry the entry to be formatted (string) |
857 @param entry entry to be formatted |
818 @return formatted entry (string) |
858 @type str |
|
859 @return formatted entry |
|
860 @rtype str |
819 """ |
861 """ |
820 if entry.startswith('"'): |
862 if entry.startswith('"'): |
821 return entry |
863 return entry |
822 elif entry.startswith("<"): |
864 elif entry.startswith("<"): |
823 entry = entry[3:] |
865 entry = entry[3:] |
842 def __genSeeListSection(self, _list, template): |
884 def __genSeeListSection(self, _list, template): |
843 """ |
885 """ |
844 Private method to generate the "see also" list section of a |
886 Private method to generate the "see also" list section of a |
845 description. |
887 description. |
846 |
888 |
847 @param _list List containing the info for the section. |
889 @param _list list containing the info for the section |
848 @param template The template to be used for the list. (string) |
890 @type list |
849 @return The list section. (string) |
891 @param template template to be used for the list |
|
892 @type str |
|
893 @return list section |
|
894 @rtype str |
850 """ |
895 """ |
851 lst = [] |
896 lst = [] |
852 for seeEntry in _list: |
897 for seeEntry in _list: |
853 seeEntryString = "".join(seeEntry) |
898 seeEntryString = "".join(seeEntry) |
854 lst.append( |
899 lst.append( |
864 |
909 |
865 def __processInlineTags(self, desc): |
910 def __processInlineTags(self, desc): |
866 """ |
911 """ |
867 Private method to process inline tags. |
912 Private method to process inline tags. |
868 |
913 |
869 @param desc One line of the description (string) |
914 @param desc one line of the description |
870 @return processed line with inline tags expanded (string) |
915 @type str |
|
916 @return processed line with inline tags expanded |
|
917 @rtype str |
871 @exception TagError raised to indicate an invalid tag |
918 @exception TagError raised to indicate an invalid tag |
872 """ |
919 """ |
873 start = desc.find("{@") |
920 start = desc.find("{@") |
874 while start != -1: |
921 while start != -1: |
875 stop = desc.find("}", start + 2) |
922 stop = desc.find("}", start + 2) |
898 |
945 |
899 def __formatDescription(self, descr): |
946 def __formatDescription(self, descr): |
900 """ |
947 """ |
901 Private method to format the contents of the documentation string. |
948 Private method to format the contents of the documentation string. |
902 |
949 |
903 @param descr The contents of the documentation string. (string) |
950 @param descr contents of the documentation string |
904 @exception TagError A tag doesn't have the correct number |
951 @type str |
905 of arguments. |
952 @return formatted contents of the documentation string |
906 @return The formatted contents of the documentation string. (string) |
953 @rtype str |
|
954 @exception TagError A tag doesn't have the correct number of arguments. |
907 """ |
955 """ |
908 if not descr: |
956 if not descr: |
909 return "" |
957 return "" |
910 |
958 |
911 paragraphs = [] |
959 paragraphs = [] |
965 lastTag = parts[0] |
1013 lastTag = parts[0] |
966 if len(parts) < 2: |
1014 if len(parts) < 2: |
967 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1015 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
968 paramList[-1][1] = parts[1] |
1016 paramList[-1][1] = parts[1] |
969 elif desc.startswith("@ptype"): |
1017 elif desc.startswith("@ptype"): |
970 inTagSection = True |
1018 raise TagError("Tag '@ptype' is deprecated, use '@type' instead\n") |
971 parts = desc.split(None, 2) |
1019 elif desc.startswith("@ireturn"): |
972 lastTag = parts[0] |
1020 raise TagError( |
973 if len(parts) < 3: |
1021 "Tag '@ireturn' is deprecated, use '@return' instead\n" |
974 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1022 ) |
975 param, type_ = parts[1:] |
1023 elif desc.startswith("@return"): |
976 for index in range(len(paramList)): |
|
977 if paramList[index][0] == param: |
|
978 paramList[index][1] = type_ |
|
979 break |
|
980 else: |
|
981 raise TagError( |
|
982 "Unknow parameter name '{0}' in {1} line.\n".format( |
|
983 param, parts[0] |
|
984 ) |
|
985 ) |
|
986 elif desc.startswith(("@return", "@ireturn")): |
|
987 inTagSection = True |
1024 inTagSection = True |
988 parts = desc.split(None, 1) |
1025 parts = desc.split(None, 1) |
989 lastTag = parts[0] |
1026 lastTag = parts[0] |
990 if len(parts) < 2: |
1027 if len(parts) < 2: |
991 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1028 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
992 returns = [parts[1]] |
1029 returns = [parts[1]] |
993 lastItem = returns |
1030 lastItem = returns |
994 elif desc.startswith("@rtype"): |
1031 elif desc.startswith("@rtype"): |
995 parts = desc.split(None, 1) |
1032 parts = desc.split(None, 1) |
996 if lastTag not in ["@return", "@ireturn"]: |
1033 if lastTag != "@return": |
997 raise TagError( |
1034 raise TagError( |
998 "{0} line must be preceded by a @return line\n".format( |
1035 "{0} line must be preceded by a @return line\n".format( |
999 parts[0] |
1036 parts[0] |
1000 ) |
1037 ) |
1001 ) |
1038 ) |
1025 lastTag = parts[0] |
1062 lastTag = parts[0] |
1026 if len(parts) < 2: |
1063 if len(parts) < 2: |
1027 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1064 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1028 yieldTypes = [parts[1]] |
1065 yieldTypes = [parts[1]] |
1029 lastItem = yieldTypes |
1066 lastItem = yieldTypes |
1030 elif desc.startswith(("@exception", "@throws", "@raise")): |
1067 elif desc.startswith(("@throws", "@raise")): |
|
1068 tag = desc.split(None, 1)[0] |
|
1069 raise TagError( |
|
1070 "Tag '{0}' is deprecated, use '@exception' instead\n".format( |
|
1071 tag |
|
1072 ) |
|
1073 ) |
|
1074 elif desc.startswith("@exception"): |
1031 inTagSection = True |
1075 inTagSection = True |
1032 parts = desc.split(None, 2) |
1076 parts = desc.split(None, 2) |
1033 lastTag = parts[0] |
1077 lastTag = parts[0] |
1034 if len(parts) < 2: |
1078 if len(parts) < 2: |
1035 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1079 raise TagError("Wrong format in {0} line.\n".format(parts[0])) |
1248 |
1292 |
1249 def getQtHelpKeywords(self): |
1293 def getQtHelpKeywords(self): |
1250 """ |
1294 """ |
1251 Public method to retrieve the parts for the QtHelp keywords section. |
1295 Public method to retrieve the parts for the QtHelp keywords section. |
1252 |
1296 |
1253 @return list of tuples containing the name (string) and the ref |
1297 @return list of tuples containing the name and the ref. The ref is without |
1254 (string). The ref is without the filename part. |
1298 the filename part. |
|
1299 @rtype list of tuples of (str, str) |
1255 """ |
1300 """ |
1256 if not self.generated: |
1301 if not self.generated: |
1257 self.genDocument() |
1302 self.genDocument() |
1258 |
1303 |
1259 return self.keywords |
1304 return self.keywords |