-
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
fix: add hardcoded IAM references temporarily #209
Conversation
docfx_yaml/extension.py
Outdated
# 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 \ |
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.
The indentation here is pretty gnarly (for
-> for
-> if
-> if
-> if
with a couple continue
s). Can we simplify this? Perhaps with a helper function?
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, updated to use a helper function.
Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
Thank you! Please take a look again. |
docfx_yaml/extension.py
Outdated
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 |
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.
Does "its name" refer to current_name
?
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.
Yes. Updated comment to clarify this.
docfx_yaml/extension.py
Outdated
converted_words: List[str], | ||
hard_coded_references: Dict[str, str] = None | ||
): | ||
"""Given a word, check if it contains a reference keyword we should convert. |
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.
"Check" sounds like a boolean. So, I'd suggest something like resolve_cross_reference
and perhaps return None
if nothing is found instead of ""
.
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.
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.
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.
👍 Please update this docstring. Something like Returns the resolved cross reference for current_word, if it exists
.
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.
docfx_yaml/extension.py
Outdated
current_name: str, | ||
words: List[str], | ||
index: int, | ||
word: str, |
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.
The word
and current_name
args are confusing to me.
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.
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.
docfx_yaml/extension.py
Outdated
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>" |
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.
Could just return at this point.
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.
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
words = content.split(" ") | ||
new_words = [] | ||
converted_words = [] |
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.
Why a list instead of a dictionary from word to converted word?
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.
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.
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 :) |
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.
Sorry for all the comments -- trying to wrap my head around this. 😄
docfx_yaml/extension.py
Outdated
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: |
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.
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?
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.
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!
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.
It looks like we split on " "
? So, do we need to worry about foo.Foo
being split up?
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.
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.
docfx_yaml/extension.py
Outdated
|
||
# Contains a list of words that is not a valid reference or converted | ||
# references. | ||
visited_words = [] |
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.
What about processed
, resolved
, or converted
content
? Or even result
?
(Visited makes me think of doing a graph traversal.)
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.
Processed sounds good!
docfx_yaml/extension.py
Outdated
converted_words: List[str], | ||
hard_coded_references: Dict[str, str] = None | ||
): | ||
"""Given a word, check if it contains a reference keyword we should convert. |
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.
👍 Please update this docstring. Something like Returns the resolved cross reference for current_word, if it exists
.
docfx_yaml/extension.py
Outdated
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 |
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.
Total nit: perhaps current_word
should be the first arg?
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.
Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
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.
No worries, thank you for taking a detailed look! :D
docfx_yaml/extension.py
Outdated
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: |
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.
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!
docfx_yaml/extension.py
Outdated
|
||
# Contains a list of words that is not a valid reference or converted | ||
# references. | ||
visited_words = [] |
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.
Processed sounds good!
docfx_yaml/extension.py
Outdated
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 |
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.
docfx_yaml/extension.py
Outdated
converted_words: List[str], | ||
hard_coded_references: Dict[str, str] = None | ||
): | ||
"""Given a word, check if it contains a reference keyword we should convert. |
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.
docfx_yaml/extension.py
Outdated
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: |
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.
It looks like we split on " "
? So, do we need to worry about foo.Foo
being split up?
docfx_yaml/extension.py
Outdated
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 |
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.
Last arg question - what exactly is keyword
?
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.
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.
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.
Made some additional modifications, please take a look again!
docfx_yaml/extension.py
Outdated
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: |
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.
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.
docfx_yaml/extension.py
Outdated
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 |
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.
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.
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.