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 accidental deletion of GitHub source links for methods #940

Merged
merged 19 commits into from
Feb 29, 2024

Conversation

Eric-Arellano
Copy link
Collaborator

Part of #517.

Turns out that we would accidentally delete all the GitHub links for methods because we were using closest().remove() rather than .closest().first().remove(). That means that we'd only have the link for the class definition and not individual methods, which defeats the point of precise source code links from #517.

Historical API docs

However, the behavior to not show methods is actually quite sensible for our API docs, where we were using sphinx.ext.viewcode rather than sphinx.ext.linkcode. That meant that we could only link to the overall file, rather than specific line numbers. So, it's not very useful to keep linking to the overall file for every method since they will each have the same value and the class definition already has the value. So, we check if the link is for a method and proactively remove it if so.

This change to proactively remove method links changes some historical API doc versions, but not others. Why? It only removes the links if we were doing method inlining, where the method had a dedicated HTML page originally. That's because the .remove() line wouldn't impat the distinct HTML pages.

Copy link
Member

@frankharkins frankharkins left a comment

Choose a reason for hiding this comment

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

Thank you!

expect(result).toEqual(
`<a href="https://github.com/Qiskit/qiskit/blob/stable/1.0/qiskit/utils/deprecation.py#L24-L101" title="view source code">GitHub</a>`,
` <a href="https://github.com/Qiskit/qiskit/blob/stable/1.0/qiskit/utils/deprecation.py#L24-L101" title="view source code">GitHub</a>`,
Copy link
Member

Choose a reason for hiding this comment

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

Is the extra space important? If so maybe a quick comment so we don't delete it at some point in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is #915. I moved where the space is added as a refactor of #915.

@Eric-Arellano Eric-Arellano added this pull request to the merge queue Feb 29, 2024
Merged via the queue into main with commit ca63bab Feb 29, 2024
5 checks passed
@Eric-Arellano Eric-Arellano deleted the EA/fix-github-links branch February 29, 2024 22:06
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
Part of Qiskit#517.

Turns out that we would accidentally delete all the GitHub links for
methods because we were using `closest().remove()` rather than
`.closest().first().remove()`. That means that we'd only have the link
for the class definition and not individual methods, which defeats the
point of precise source code links from
Qiskit#517.

## Historical API docs

However, the behavior to not show methods is actually quite sensible for
our API docs, where we were using `sphinx.ext.viewcode` rather than
`sphinx.ext.linkcode`. That meant that we could only link to the overall
file, rather than specific line numbers. So, it's not very useful to
keep linking to the overall file for every method since they will each
have the same value and the class definition already has the value. So,
we check if the link is for a method and proactively remove it if so.

This change to proactively remove method links changes some historical
API doc versions, but not others. Why? It only removes the links if we
were doing method inlining, where the method had a dedicated HTML page
originally. That's because the `.remove()` line wouldn't impat the
distinct HTML pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants