Skip to content
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

fix: add hardcoded IAM references temporarily #209

Merged
merged 15 commits into from
May 24, 2022
Merged

fix: add hardcoded IAM references temporarily #209

merged 15 commits into from
May 24, 2022

Conversation

dandhlee
Copy link
Collaborator

At the moment, there are 4 IAM libraries and it is very unclear to users which IAM library is referenced in the documentation. To make this worse, some of them don't have documentation that is generated to point to. The IAM team is reviewing combining all the libraries under python-iam, but until then it will remain unclear.

To temporarily address this, pointing the IAM references to the GitHub repository where the source code is located. This hard coded reference list can also be used for other common libraries that the documentation is missing references to, until we can figure out Intersphinx and hosting that on c.g.c.

Filed #208 to track removing the hard coded references in the future.

Fixes b/232773389.

  • Tests pass

@dandhlee dandhlee requested a review from a team as a code owner May 17, 2022 05:41
@dandhlee dandhlee requested a review from a team May 17, 2022 05:41
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label May 17, 2022
docfx_yaml/extension.py Show resolved Hide resolved
# Using counter to check if the entry is already a cross reference.
for index, word in enumerate(words):
cross_reference = ""
for keyword in entry_names:
if keyword != current_name and keyword not in current_name and keyword in word:
if keyword in hard_coded_references:
if "<a" in words[index-1] or \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here is pretty gnarly (for -> for -> if -> if -> if with a couple continues). Can we simplify this? Perhaps with a helper function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, updated to use a helper function.

docfx_yaml/extension.py Outdated Show resolved Hide resolved
dandhlee and others added 2 commits May 17, 2022 11:37
Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels May 17, 2022
@dandhlee
Copy link
Collaborator Author

Thank you! Please take a look again.

@dandhlee dandhlee requested a review from tbpg May 17, 2022 18:54
docfx_yaml/extension.py Show resolved Hide resolved
def convert_cross_references(content: str, current_name: str, entry_names: List[str]):
"""Finds and replaces references that should be a cross reference in given content.

This should not convert any references that contain its name, i.e. if we're processing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "its name" refer to current_name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Updated comment to clarify this.

converted_words: List[str],
hard_coded_references: Dict[str, str] = None
):
"""Given a word, check if it contains a reference keyword we should convert.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Check" sounds like a boolean. So, I'd suggest something like resolve_cross_reference and perhaps return None if nothing is found instead of "".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt icky mixing between None and an empty string, however I think in this case it makes sense that we indeed return None instead of an empty string if a cross reference has not been found. Updating with suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Please update this docstring. Something like Returns the resolved cross reference for current_word, if it exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

docfx_yaml/extension.py Outdated Show resolved Hide resolved
Comment on lines 1421 to 1424
current_name: str,
words: List[str],
index: int,
word: str,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word and current_name args are confusing to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated word -> current_word and current_name -> current_object_name. However, checking for it in this function seemed useless so I removed it from this function and moved it up, happy to take any other variable name suggestions still.

if keyword in hard_coded_references:
if "<a" not in words[index-1] and \
not (converted_words and f"<a href=\"{hard_coded_references[keyword]}" in converted_words[-1]):
cross_reference = f"<a href=\"{hard_coded_references[keyword]}\">{keyword}</a>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just return at this point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was better style to put the return at the end, but I have no preference. Updated to reflect suggestion.

docfx_yaml/extension.py Outdated Show resolved Hide resolved
docfx_yaml/extension.py Outdated Show resolved Hide resolved
words = content.split(" ")
new_words = []
converted_words = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a list instead of a dictionary from word to converted word?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the name is still throwing off. As we traverse the original list of words, we still need to check against the converted list of words and order matters. At the end, I use this to simply convert to a string using a join. Will update the name so it's not misleading.

@dandhlee
Copy link
Collaborator Author

Thank you! Made necessary modifications, updated existing unit test for checking against the name itself and name change in the test. Please take a look again :)

@dandhlee dandhlee requested a review from tbpg May 18, 2022 05:50
Copy link
Contributor

@tbpg tbpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the comments -- trying to wrap my head around this. 😄

docfx_yaml/extension.py Outdated Show resolved Hide resolved
cross_reference = f"<xref uid=\"{keyword}\">{keyword}</xref>"
new_words.append(word.replace(keyword, cross_reference))
# Do not convert references to itself.
if keyword in current_object_name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies if this was asked before. Why is this in and not ==? I'm imagining something like foo.Foo and foo.FooBar. I suppose there might be other punctuation or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we check for foo, we don't check to convert references for foo.* yet, because the parents (i.e. foo is the parent of foo.Foo) come before its children and would try to convert foo.Foo as <xref uid='foo'>foo</xref>.Foo instead of <xref uid='foo.Foo'>foo.Foo</xref>. On the contrary, foo.Foo in foo doesn't hold and will properly be handled later, as shown here for google.cloud.bigquery_storage_v1.types.ReadSession.TableReadOptions. Totally my fault for not explaining clearly, I will add a comment to clarify!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we split on " "? So, do we need to worry about foo.Foo being split up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nay, they will always appear in tact as one word since split(" ") needs the words to have whitespace in between. If it does, that's a docstring typo rather than logical overhead from this code.


# Contains a list of words that is not a valid reference or converted
# references.
visited_words = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about processed, resolved, or converted content? Or even result?

(Visited makes me think of doing a graph traversal.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processed sounds good!

docfx_yaml/extension.py Outdated Show resolved Hide resolved
converted_words: List[str],
hard_coded_references: Dict[str, str] = None
):
"""Given a word, check if it contains a reference keyword we should convert.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Please update this docstring. Something like Returns the resolved cross reference for current_word, if it exists.

Args:
words: list of words used to check and compare content before and after `current_word`
index: index position of `current_word` within words
current_word: current word being looked at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total nit: perhaps current_word should be the first arg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

docfx_yaml/extension.py Outdated Show resolved Hide resolved
dandhlee and others added 2 commits May 18, 2022 08:31
Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
Copy link
Collaborator Author

@dandhlee dandhlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thank you for taking a detailed look! :D

cross_reference = f"<xref uid=\"{keyword}\">{keyword}</xref>"
new_words.append(word.replace(keyword, cross_reference))
# Do not convert references to itself.
if keyword in current_object_name:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we check for foo, we don't check to convert references for foo.* yet, because the parents (i.e. foo is the parent of foo.Foo) come before its children and would try to convert foo.Foo as <xref uid='foo'>foo</xref>.Foo instead of <xref uid='foo.Foo'>foo.Foo</xref>. On the contrary, foo.Foo in foo doesn't hold and will properly be handled later, as shown here for google.cloud.bigquery_storage_v1.types.ReadSession.TableReadOptions. Totally my fault for not explaining clearly, I will add a comment to clarify!


# Contains a list of words that is not a valid reference or converted
# references.
visited_words = []
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processed sounds good!

docfx_yaml/extension.py Outdated Show resolved Hide resolved
Args:
words: list of words used to check and compare content before and after `current_word`
index: index position of `current_word` within words
current_word: current word being looked at
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

converted_words: List[str],
hard_coded_references: Dict[str, str] = None
):
"""Given a word, check if it contains a reference keyword we should convert.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dandhlee dandhlee requested a review from tbpg May 18, 2022 13:23
tbpg
tbpg previously approved these changes May 18, 2022
cross_reference = f"<xref uid=\"{keyword}\">{keyword}</xref>"
new_words.append(word.replace(keyword, cross_reference))
# Do not convert references to itself.
if keyword in current_object_name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we split on " "? So, do we need to worry about foo.Foo being split up?

current_word: current word being looked at
words: list of words used to check and compare content before and after `current_word`
index: index position of `current_word` within words
keyword: reference keyword to check against
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last arg question - what exactly is keyword?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be last! I'm not sure why I stuck with that word in this context, they're UIDs extracted from Sphinx. Updated to say UIDs instead.

@dandhlee dandhlee requested a review from tbpg May 20, 2022 22:36
@dandhlee dandhlee dismissed tbpg’s stale review May 20, 2022 22:37

made additional modifications to the PR

Copy link
Collaborator Author

@dandhlee dandhlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some additional modifications, please take a look again!

cross_reference = f"<xref uid=\"{keyword}\">{keyword}</xref>"
new_words.append(word.replace(keyword, cross_reference))
# Do not convert references to itself.
if keyword in current_object_name:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nay, they will always appear in tact as one word since split(" ") needs the words to have whitespace in between. If it does, that's a docstring typo rather than logical overhead from this code.

current_word: current word being looked at
words: list of words used to check and compare content before and after `current_word`
index: index position of `current_word` within words
keyword: reference keyword to check against
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be last! I'm not sure why I stuck with that word in this context, they're UIDs extracted from Sphinx. Updated to say UIDs instead.

@dandhlee dandhlee merged commit 5dc99d2 into main May 24, 2022
@dandhlee dandhlee deleted the fix_iam branch May 24, 2022 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants