@@ -138,6 +138,12 @@ class Bcolors:
138138 # Modules and Classes are similar types.
139139 MODULE : CLASS ,
140140 CLASS : CLASS ,
141+ # Methods and Functions are similar types.
142+ METHOD : METHOD ,
143+ FUNCTION : METHOD ,
144+ # Properties and Attributes are similar types.
145+ PROPERTY : PROPERTY ,
146+ ATTRIBUTE : PROPERTY ,
141147}
142148# Construct a mapping of name and content for each unique summary type entry.
143149_ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE = {
@@ -147,6 +153,8 @@ class Bcolors:
147153# Mapping for each summary page entry's file name and entry name.
148154_FILE_NAME_AND_ENTRY_NAME_BY_SUMMARY_TYPE = {
149155 CLASS : ('summary_class.yml' , "Classes" ),
156+ METHOD : ('summary_method.yml' , "Methods" ),
157+ PROPERTY : ('summary_property.yml' , "Properties and Attributes" ),
150158}
151159
152160# Disable blib2to3 output that clutters debugging log.
@@ -1384,12 +1392,51 @@ def _find_and_add_summary_details(
13841392 if summary_type in [CLASS ]:
13851393 name_to_use = f"[{ uid } ]({ cgc_url } { uid } )"
13861394
1387- _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE [summary_type ][1 ].append ({
1388- "uid" : uid ,
1395+ _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE [summary_type ][1 ].append ({
1396+ "uid" : uid ,
1397+ "name" : name_to_use ,
1398+ "fullName" : uid ,
1399+ "isExternal" : False ,
1400+ })
1401+ return
1402+
1403+ # if summary_type in [METHOD, PROPERTY]:
1404+ short_name = yaml_data .get ("name" , "" )
1405+ name_to_use = uid
1406+ if not (class_name := yaml_data .get ("class" , "" )):
1407+ class_name = yaml_data .get ("module" , "" )
1408+ anchor_name = f"#{ class_name .replace ('.' , '_' )} _{ short_name } "
1409+ # Extract the first summary line by attempting to detect the first sentence.
1410+ summary = yaml_data .get ("summary" , "" )
1411+ first_summary_line = min (
1412+ summary .split (". " )[0 ],
1413+ summary .split (".\n " )[0 ],
1414+ summary .split ("\n \n " )[0 ],
1415+ key = len ,
1416+ )
1417+ if first_summary_line and first_summary_line [- 1 ] != "." :
1418+ first_summary_line += "."
1419+
1420+ summary_to_use = (
1421+ f"{ first_summary_line } \n \n "
1422+ f"See more: [{ name_to_use } ]({ cgc_url } { class_name } { anchor_name } )"
1423+ )
1424+
1425+ fields = {
1426+ "uid" : f"{ uid } -summary" ,
13891427 "name" : name_to_use ,
1428+ "summary" : summary_to_use ,
13901429 "fullName" : uid ,
1391- "isExternal" : False ,
1392- })
1430+ "type" : 'method' ,
1431+ }
1432+
1433+ if summary_type == METHOD :
1434+ fields ["syntax" ] = {
1435+ "content" : yaml_data .get ("syntax" ).get ("content" ) if yaml_data .get ("syntax" ) else ""
1436+ }
1437+ _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE [summary_type ][1 ].append (
1438+ fields
1439+ )
13931440
13941441
13951442def _render_summary_content (
@@ -1399,21 +1446,23 @@ def _render_summary_content(
13991446 library_name : str ,
14001447) -> _yaml_type_alias :
14011448 """Returns the summary content in appropriate YAML format to write."""
1402- summary_content = {}
1449+ summary_content = {
1450+ "items" : [{
1451+ 'uid' : f'{ summary_type .lower ()} -summary' ,
1452+ 'name' : entry_name ,
1453+ 'fullName' : f'{ entry_name } Summary' ,
1454+ 'langs' : ['python' ],
1455+ 'type' : 'package' ,
1456+ 'summary' : f'Summary of entries of { entry_name } for { library_name } .' ,
1457+ 'children' : children_name_and_summary_content [0 ],
1458+ }]
1459+ }
14031460
14041461 if summary_type in [CLASS ]:
1405- summary_content = {
1406- "items" : [{
1407- 'uid' : f'{ summary_type .lower ()} -summary' ,
1408- 'name' : entry_name ,
1409- 'fullName' : f'{ entry_name } Summary' ,
1410- 'langs' : ['python' ],
1411- 'type' : 'package' ,
1412- 'summary' : f'Summary of entries of { entry_name } for { library_name } .' ,
1413- 'children' : children_name_and_summary_content [0 ],
1414- }],
1415- 'references' : children_name_and_summary_content [1 ],
1416- }
1462+ summary_content ["references" ] = children_name_and_summary_content [1 ]
1463+
1464+ if summary_type in [METHOD , PROPERTY ]:
1465+ summary_content ["items" ].extend (children_name_and_summary_content [1 ])
14171466
14181467 return summary_content
14191468
@@ -1971,6 +2020,8 @@ def convert_module_to_package_if_needed(obj):
19712020 "name" : f"{ app .config .project } APIs" ,
19722021 "items" : [
19732022 {"name" : "Classes" , "href" : "summary_class.yml" },
2023+ {"name" : "Methods" , "href" : "summary_method.yml" },
2024+ {"name" : "Properties and Attributes" , "href" : "summary_property.yml" },
19742025 ],
19752026 }
19762027 )
0 commit comments