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
Set refdoc to be used by missing-reference, intersphinx #9685
Conversation
I can't immediately judge if this is the right solution, but I think it is very similar to what was suggested in #7634 and thereby also fix that. |
Yes, I have read the issue. This looks like the same problem, but different solution. I think we both agree that the So we should only decide where in that function we added it as an attribute or pass it as an extra argument. |
While the ideal thing perhaps would be to add it as an extra argument for the event, that would be a breaking change. The attribute already exists so I think your suggested solution is the right one. |
As I commented at #7634 (comment), this is a bug of the code that generates the pending_xref node. But, as you said, I understand this code automatically recovers the missing off topic: I don't understand why the |
I semi agree with you. As it should be set on generation of the nodes, then we could fix it there. But what code does generate the nodes?
Why it is needed, is because intersphinx uses it to determine the relative path of the node to the root of the package, so that it can resolve relative paths to references correctly. |
I'm not sure. We need to investigate if needed.
AFAIK, it is always the same as |
The use of Otherwise I suggest we just go for |
sadly, no idea anymore. |
I have discovered two places where a
So the second option is the cause of the problem. I think we can set the |
Unfortunately it's not only in those two places:
It seems that the |
I am just a user of Sphinx. As Sphinx is pretty big, I don't have the complete overview how everything is/should be working. Therefore I can't say which attributes are/should be required and which are/should be optional. Also it is undocumented what the meaning of all attributes are(So it is unknown which attributes there are). So the best solution would be to gather all the attributes for all nodes. Document their value, purpose and which node requires which attribute. And combine this with making the attributes required in the code as well. I would prefer merging this PR as a partial fix. I don't mind my solution or your solution (#9685 (comment)) |
As I commented on it, I prefer to fill the Additionally, as I commented as "off topic", the |
@tk0miya I have updated the PR to match your suggestion. I also changed the target branch to 4.x, as you added this PR to the 4.3.0 milestone. |
@tk0miya anything that is blocking this PR to be approved/merged? |
Sorry for not responding long. I'm back now. It seems good to me. I'll merge this after CI passed. |
Merged. Thank you for your contribution! |
Feature or Bugfix
Bugfix
Purpose
Intersphinx checks for
refdoc
attribute in node during themissing-reference
event. To determine to correct relative reference uri.sphinx/sphinx/ext/intersphinx.py
Lines 330 to 332 in cf38356
It is called from
post_transforms
, all other options that are tried/checked before, do get a separaterefdoc
as an argument. Though themissing-reference
event only gets it if it was already in the node, as it doesn't have a separaterefdoc
argument.sphinx/sphinx/transforms/post_transforms/__init__.py
Lines 98 to 100 in cf38356
I have not experienced a situation yet, where it was already set.
By not providing the
missing-reference
event with the back-up 'refdoc' fromsphinx/sphinx/transforms/post_transforms/__init__.py
Line 81 in cf38356
Relative reference uri's don't work in intersphinx.
So either we need to set the
refdoc
attribute to node or change the API ofmissing-reference
, so that it acceptsrefdoc
as a separate argument. I choose the first option, but I am open to implement the second one if you prefer that one.P.S.: also the viewcode extension expects the
refdoc
attribute of thenode
to be set. So that would favor the first option, which I implemented.sphinx/sphinx/ext/viewcode.py
Lines 204 to 205 in cf38356
Detail
By not having the
refdoc
in intersphinx, it doesn't know how deep you are in your package, therefore it can't determine relative paths to references. It will use assume your are in the root of your package, which will generate broken links as the depth mismatches.Relates
Fixes #7634