-
Notifications
You must be signed in to change notification settings - Fork 41
Intersphinx - RefType - Use objtypes inventory as fallback mechanism #144
Intersphinx - RefType - Use objtypes inventory as fallback mechanism #144
Conversation
cc @humitos |
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.
Hi! Thanks for your PR! 🤟🏼
I think this is correct. I haven't tested it yet, tho.
It would be good to have some tests for this case.
Also, are you aware of other synonyms (like py:method
and py:meth
) that may make sense to add here as well? In that case, we should add them as well.
Also also, do you know if this works for all domains or only for Python (e.g. py:
)? In that case, we should restrict it to Python only.
Thanks, @humitos! I'll look into adding some tests for this. About the other questions, I'm not aware about other synonyms or the python only domain, I'll update the code to handle only python in the meantime :P |
I found another case. |
@chrizzFTD Hi! I included your solution in #146 because I found myself having this issue. However, I didn't finish this work. It would be good if you have some time to update your PR with the latest changes from |
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.
Hi @humitos, I've updated my branch to take the recent changes from master
. I've also taken a new approach by letting fallback keys to be given by the domain for that inventory + tests.
Please let me know what you think!
One thing to note, however, is that it looks like something else might have broken recently as my project grill is no longer able to display tooltips when using this branch. Everything, both internal and intersphinx references now get stuck in a "Loading" tooltip:
If I check on an older build from a couple of weeks ago, e.g. on https://grill.readthedocs.io/en/develop/api.html, the problem does not appear. Do you know what might be the issue?
@@ -4,9 +4,13 @@ Example page | |||
This is an example page. | |||
|
|||
:ref:`This a :ref: to The Python Tutorial using intersphinx <python:tutorial-index>`. | |||
:ref:`This a :ref: to datetime.datetime Python's function using intersphinx <python:datetime-datetime>`. |
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 chose to remove these single quotes since they were causing trouble on my end, they came as:
Python’s
Found it easier to remove them since I don't find them relevant to this test, but please let me know if I should bring them back.
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.
This seems to be an encoding problem on your side. You may not be declaring the encoding properly.
|
||
:py:meth:`collections.Counter.elements` to test intersphinx methods. | ||
|
||
:py:func:`sum` to test intersphinx functions. |
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.
Without the changes, these two lines above do not have the "hoverxref ... reference external"
html class added.
Yes. It's already fixed. There was a problem with CORS and the fix didn't go out yet. I solved it at readthedocs/readthedocs.org#8543. We are deploying that fix tomorrow and the tooltips should work properly in your docs with this branch. |
@chrizzFTD can you confirm that tooltips work on your documentation using |
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.
Looks really good! The new approach is way better since it will always bring all the supported reftypes
. I left some suggestions to consider. Let me know!
# Read the Docs' link does have hoverxref enabled | ||
r'<a class="hoverxref modal reference external" href="https://docs.readthedocs.io/en/stable/config-file/v2.html#python" title="\(in Read the Docs v\d\d?.\d\d?.\d+\)"><span class="xref std std-ref">This a :ref: to Config File v2 Read the Docs’ page using intersphinx</span></a>', | ||
r'<a class=\"hoverxref modal reference external\" href=\"https://docs.readthedocs.io/en/stable/config-file/v2.html#python\" title=\"\(in Read the Docs v\d\d?.\d\d?.\d+\)\"><span class=\"xref std std-ref\">This a :ref: to Config File v2 Read the Docs page using intersphinx</span></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.
These \"
are not required. It should just work with regular "
since the string is defined with '
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.
This double quote character was not being escaped by the regular expression when I ran the tests locally, so it never matched, do you know of any setting that would cause this?
r'<a class=\"hoverxref tooltip reference external\" href=\"https://docs.python.org/3/tutorial/index.html#tutorial-index\" title=\"\(in Python v3.\d\d?\)\"><span class=\"xref std std-ref\">This a :ref: to The Python Tutorial using intersphinx</span></a>', | ||
r'<a class=\"hoverxref tooltip reference external\" href=\"https://docs.python.org/3/library/datetime.html#datetime-datetime\" title=\"\(in Python v3.\d\d?\)\"><span class=\"xref std std-ref\">This a :ref: to datetime.datetime Python function using intersphinx</span></a>', | ||
r'<a class=\"hoverxref modal reference external\" href=\"https://docs.python.org/3/library/functions.html#float\" title=\"\(in Python v3.\d\d?\)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">float</span></code></a>', | ||
r'<a class=\"hoverxref tooltip reference external\" href=\"https://docs.python.org/3/library/collections.html#collections.Counter.elements\" title=\"\(in Python v3.\d\d?\)\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">collections.Counter.elements\(\)</span></code></a> to test intersphinx methods.</p>', |
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.
Can you add a comment here that this case is particular and it's for py:meth
(fallbacks) ? Also, if it's even clear to explain/understand, we can create a specific test case for these
# Intersphinx inventories may come with concrete types for domain roles. | ||
# (e.g. for python, when reftype=='meth', inventory uses "method" or "classmethod"... | ||
# so check in order, starting from the current reftype. | ||
keys_to_check = [reftype, *env_domain.objtypes_for_role(reftype)] |
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.
keys_to_check = [reftype, *env_domain.objtypes_for_role(reftype)] | |
keys_to_check = set([reftype, *env_domain.objtypes_for_role(reftype)]) |
In some cases reftype
is already included in the response from env_domain.objtypes_for_role(reftype)
, so we can create a set()
to remove duplicated ones.
Thanks @humitos ! I'll come back to this hopefully next weekend |
I think #171 should solve this issue as well. @chrizzFTD can you please confirm that the latest commit from |
@chrizzFTD We released a new version (v1.1.1) with the PR linked on it. I suppose this problem is solved now. However, feel free to re-open this PR or comment here if you find something wrong. Let me know! |
Hi @humitos, thanks a lot for the updates & apologies it took me so long to come back here on GitHub; but I can confirm that the latest release |
Great! Happy to read that 💪 |
Hi, thanks a lot for this awesome sphinx extension!
Issue
I came across a small issue where intersphinx class methods would not load hoverxref tooltips on my project at grill.rtfd.io. This was strange since classes from the same intersphinx project would work fine.
Discoveries
On my RST doc file, I refer to the intersphinx grill.names.UsdAsset.get_anonymous method like so:
For
hoverxref
, the inventory loaded here:sphinx-hoverxref/hoverxref/extension.py
Lines 225 to 226 in eed8700
Looks like this:
If I replace the RST text to use
method
like so:The translation fails with a message like:
WARNING: Unknown interpreted text role "py:method".
So it looks like it must be left as
py:meth
.Proposal
I've chosen to use a "fallback" mechanism as presented on this PR.
You can see it working on the hint block from this docs:
If this PR is not needed and there is something different I should do on my side, please let me know!