feat: add summary page for Classes and Modules#361
Conversation
|
|
||
| file_path_to_use = os.path.join(normalized_outdir, file_name) | ||
| with open(file_path_to_use, "w") as summary_file_obj: | ||
| summary_file_obj.write("### YamlMime:UniversalReference\n") |
There was a problem hiding this comment.
Nit: set a constant for the docfx YAML type string
| CLASS: CLASS, | ||
| } | ||
| # Construct a mapping of name and content for each unique summary type entry. | ||
| _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE = { |
There was a problem hiding this comment.
Can this be converted to a dataclass? Something like:
class SummaryEntry:
name: str
summary: str
For now it seems like there's just one summary type CLASS, so I think this information can be captured in just one data class. This would allow us to not use i-indexing below, which I think makes this more readable.
There was a problem hiding this comment.
It's a bit tricky, I need to keep track of all the entries that's been submitted already. Either we need to keep an extra list, otherwise converting this to a dataclass we'd lose being able to have a sequence of information, instead we'll have Sequence[SummaryEntry] and not be able to easily go through the info :/
| DEPRECATED: 'deprecated', | ||
| } | ||
|
|
||
| _SUMMARY_TYPE_BY_ITEM_TYPE = { |
There was a problem hiding this comment.
Nit: Maybe use _SUMMARY_GROUP instead? The phrasing can get a little bit confusing because you're working with Python types as well.
There was a problem hiding this comment.
This was a preferred style for mappings (summary_by_item[item] gives summary) - I could also just omit the types if that makes it better
| uid = yaml_data.get("uid", "") | ||
| item_to_add = uid if summary_type == CLASS else f"{uid}-summary" | ||
|
|
||
| if item_to_add not in _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE[summary_type][0]: |
There was a problem hiding this comment.
I think you can avoid this check if your use a Set for your uids.
There was a problem hiding this comment.
I think the problem was that I ran into the same items twice, not that the UIDs are not unique :/ I was seeing duplicate entries for each entry, but the UIDs are definitely unique (google.cloud.package.module.item)
| continue | ||
|
|
||
| _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE[summary_type][1].append( | ||
| _find_summary_details(entry, summary_type, cgc_url) |
There was a problem hiding this comment.
Nit: I think because the return value of _find_summary_details is only used to update the global mapping, I would just append the summary detail dict within the function.
There was a problem hiding this comment.
Done! Good point.
| ], | ||
| } | ||
| ) | ||
| cgc_url = ( |
There was a problem hiding this comment.
Nit: Move this below writing the toc file.
| 'langs': ['python'], | ||
| 'type': 'package', | ||
| 'summary': f'Summary of entries of {entry_name} for {library_name}.', | ||
| 'children': children_name_and_summary_content[0], |
There was a problem hiding this comment.
Nit: consider sorting by class/module name here.
There was a problem hiding this comment.
It's already sorted by UID!
|
|
||
|
|
||
| def _render_summary_content( | ||
| children_name_and_summary_content: Sequence[Sequence[str]], |
There was a problem hiding this comment.
Could be mistaken here, but isn't this type Sequence[Sequence[ str | dict ] or Sequence[Sequence[ str | _yaml_type_alias ] ? The first sequence contains the list of uids, the second sequence contains the dict of YAML fields for references.
There was a problem hiding this comment.
You're right. Done.
| 'langs': ['python'], | ||
| 'type': 'package', | ||
| 'summary': f'Summary of entries of {entry_name} for {library_name}.', | ||
| 'children': children_name_and_summary_content[0], |
There was a problem hiding this comment.
Doesn't this need to be converted into a YAML list?
Something like:
reduce(lambda x, y: y + '\n - ' + x , children_name_and_summary_content[0])
There was a problem hiding this comment.
Nope, that gets handled already!
dandhlee
left a comment
There was a problem hiding this comment.
Verified that the changes did not affect produced result. Please take a look again!
|
|
||
| file_path_to_use = os.path.join(normalized_outdir, file_name) | ||
| with open(file_path_to_use, "w") as summary_file_obj: | ||
| summary_file_obj.write("### YamlMime:UniversalReference\n") |
| 'langs': ['python'], | ||
| 'type': 'package', | ||
| 'summary': f'Summary of entries of {entry_name} for {library_name}.', | ||
| 'children': children_name_and_summary_content[0], |
There was a problem hiding this comment.
It's already sorted by UID!
|
|
||
|
|
||
| def _render_summary_content( | ||
| children_name_and_summary_content: Sequence[Sequence[str]], |
There was a problem hiding this comment.
You're right. Done.
| uid = yaml_data.get("uid", "") | ||
| item_to_add = uid if summary_type == CLASS else f"{uid}-summary" | ||
|
|
||
| if item_to_add not in _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE[summary_type][0]: |
There was a problem hiding this comment.
I think the problem was that I ran into the same items twice, not that the UIDs are not unique :/ I was seeing duplicate entries for each entry, but the UIDs are definitely unique (google.cloud.package.module.item)
| CLASS: CLASS, | ||
| } | ||
| # Construct a mapping of name and content for each unique summary type entry. | ||
| _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE = { |
There was a problem hiding this comment.
It's a bit tricky, I need to keep track of all the entries that's been submitted already. Either we need to keep an extra list, otherwise converting this to a dataclass we'd lose being able to have a sequence of information, instead we'll have Sequence[SummaryEntry] and not be able to easily go through the info :/
| DEPRECATED: 'deprecated', | ||
| } | ||
|
|
||
| _SUMMARY_TYPE_BY_ITEM_TYPE = { |
There was a problem hiding this comment.
This was a preferred style for mappings (summary_by_item[item] gives summary) - I could also just omit the types if that makes it better
| 'langs': ['python'], | ||
| 'type': 'package', | ||
| 'summary': f'Summary of entries of {entry_name} for {library_name}.', | ||
| 'children': children_name_and_summary_content[0], |
There was a problem hiding this comment.
Nope, that gets handled already!
| ], | ||
| } | ||
| ) | ||
| cgc_url = ( |
| continue | ||
|
|
||
| _ENTRY_NAME_AND_ENTRY_CONTENT_BY_SUMMARY_TYPE[summary_type][1].append( | ||
| _find_summary_details(entry, summary_type, cgc_url) |
There was a problem hiding this comment.
Done! Good point.
Curate summary pages given the entirety of the library content. Starting with Classes / Modules which are similar, then will expand to other types (Methods & Functions, and Properties & Attributes) in a followup.
Goes through all of the content, then extracts the necessary information, creating a separate
summary_class.ymlfile. Adding as a separate top level entry. See live example: https://cloud.google.com/python/docs/reference/bigframes/latest/summary_classConfirmed locally that the same page still gets produced, which was based off of #298, this PR just makes the code a bit more production quality.
summary_overviewpage is referenced but will have templates that live in the client libraries. See https://docs.google.com/document/d/1FmAOv9ald2W2Set8jPzN-gwQoE992LCWSu40KBVON28/edit?resourcekey=0-JLhux0549oJustMl46l3zA&tab=t.0 for design.Test cases would be added for goldens, however it is currently disabled.
Towards b/263399076