-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: grab repository metadata #364
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import shutil | ||
import black | ||
import logging | ||
import json | ||
|
||
from collections import defaultdict | ||
from collections.abc import MutableSet, Mapping, Sequence | ||
|
@@ -161,7 +162,25 @@ class Bcolors: | |
logging.getLogger("blib2to3").setLevel(logging.ERROR) | ||
|
||
|
||
def _grab_repo_metadata() -> Mapping[str, str] | None: | ||
"""Retrieves the repository's metadata info if found.""" | ||
try: | ||
with open('.repo-metadata.json', 'r') as metadata_file: | ||
json_content = json.load(metadata_file) | ||
# Return outside of context manager for safe close | ||
return json_content | ||
except Exception: | ||
return None | ||
|
||
|
||
def build_init(app): | ||
print("Retrieving repository metadata.") | ||
if not (repo_metadata := _grab_repo_metadata()): | ||
print("Failed to retrieve repository metadata.") | ||
app.env.library_shortname = "" | ||
else: | ||
print("Successfully retrieved repository metadata.") | ||
app.env.library_shortname = repo_metadata["name"] | ||
print("Running sphinx-build with Markdown first...") | ||
markdown_utils.run_sphinx_markdown() | ||
print("Completed running sphinx-build with Markdown files.") | ||
|
@@ -2013,18 +2032,19 @@ def convert_module_to_package_if_needed(obj): | |
markdown_utils.remove_unused_pages( | ||
added_pages, app.env.moved_markdown_pages, normalized_outdir) | ||
|
||
# Add summary pages as the second entry into the table of contents. | ||
pkg_toc_yaml.insert( | ||
1, | ||
{ | ||
"name": f"{app.config.project} APIs", | ||
"items": [ | ||
{"name": "Classes", "href": "summary_class.yml"}, | ||
{"name": "Methods", "href": "summary_method.yml"}, | ||
{"name": "Properties and Attributes", "href": "summary_property.yml"}, | ||
], | ||
} | ||
) | ||
if app.env.library_shortname: | ||
# Add summary pages as the second entry into the table of contents. | ||
pkg_toc_yaml.insert( | ||
1, | ||
{ | ||
"name": f"{app.env.library_shortname} APIs", | ||
"items": [ | ||
{"name": "Classes", "href": "summary_class.yml"}, | ||
{"name": "Methods", "href": "summary_method.yml"}, | ||
{"name": "Properties and Attributes", "href": "summary_property.yml"}, | ||
], | ||
} | ||
) | ||
|
||
toc_file = os.path.join(normalized_outdir, 'toc.yml') | ||
with open(toc_file, 'w') as writable: | ||
|
@@ -2040,7 +2060,7 @@ def convert_module_to_package_if_needed(obj): | |
|
||
cgc_url = ( | ||
"https://cloud.google.com/python/docs/reference/" | ||
f"{app.config.project}/latest/" | ||
f"{app.env.library_shortname}/latest/" | ||
) | ||
yaml_entry_line = "### YamlMime:UniversalReference\n" | ||
# Output files | ||
|
@@ -2086,9 +2106,11 @@ def convert_module_to_package_if_needed(obj): | |
file_name_set.add(filename) | ||
|
||
for entry in yaml_data: | ||
if not app.env.library_shortname: | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would apply to the whole library, right? If so, I think you can just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, done. |
||
summary_type = _SUMMARY_TYPE_BY_ITEM_TYPE.get(entry.get("type")) | ||
if not (summary_type): | ||
continue | ||
continue | ||
|
||
_find_and_add_summary_details(entry, summary_type, cgc_url) | ||
|
||
|
@@ -2105,7 +2127,7 @@ def convert_module_to_package_if_needed(obj): | |
children_names_and_content, | ||
entry_name, | ||
summary_type, | ||
app.config.project, | ||
app.env.library_shortname, | ||
) | ||
|
||
file_path_to_use = os.path.join(normalized_outdir, file_name) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: import ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I was able to sort through the first party libraries.