You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How do you use the right "Edit in Github" url for generated files? #1269
Originally posted by vnmabus March 24, 2023
For generated files, such as examples generated with sphinx-gallery or API reference pages generated with autosummary, the "Edit in Github" link generates a 404 error.
It is possible to redirect them to the original file somehow? In that case, how?
@Nauin2 whatever lib you use to generate API documentation (auto-api or autosummary) the mechanism is the same:
the extention build files on the fly in .rst that will then be interpreted at build time. I don't think I have access to source file at any step so I don't have any way to reach the github source file.
As a workaround you can still use the solution referenced in #477 by building a specific directive that will override the link using javascript.
What we are missing here is a good idea to capture the source file information whatever the VCS system (github, gitlab, gitea...).
If I understand correctly, you need a link from the autogenerated .rst file to the source code, which could be anywhere in the repository.
In case of autosummary, it could be possible to alter the template with which the .rst files are generated and save the file directory within the .rst.
Okay. Maybe another idea, again autosummary specific. The names of the autogenerated .rst files follow the dot notation of python. Using, e.g., the getfile function of the inspect module the filepath to the source could be retrievable.
If someone changes the api folder name or if the template is already altered by the user himself I will have no guarantee that the hack will work. This is a theme, we don't adapt files generated by other extensions it would be impossible to keep up with their release cycle.
what could be done is:
you change the template on your side
I help you build a directive with few parameters
we document it in the "extend this theme section"
So it will force user to code something yes but it will be useful for all user whatever the api extention they are using. what do you think ?
AFAIK no real progress. There is an open PR that allows to set the secondary sidebar templates on a per-page basis, which might make it easy to simply omit the source link on generated pages (using a glob pattern). But no progress on getting them to link to the actual source files
The third method generates the correct links during Sphinx's HTML build process, as used by the author of Suggested way to customize "Edit this page" link based on document #477. This approach ensures correct links are generated at build time, avoids unnecessary runtime overhead, and is relatively simple. I recommend this method the most, and I think it's perfect.
Activity
pllim commentedon Jul 10, 2023
(Thanks for the tips! I am re-posting here so I can find it in the future.)
@OriolAbril
In case it helps, we use the custom template approach for ArviZ: https://github.com/arviz-devs/arviz/blob/main/doc/_templates/edit-this-page.html. It should be the same as the one in the pydata-sphinx-theme repo but with the extra "generated" not in sourcename bit, we always use "generated" as toctree dir for autosummary. This way all pages get the button (e.g. https://python.arviz.org/en/stable/user_guide/label_guide.html) except for api generated ones (e.g. https://python.arviz.org/en/stable/api/generated/arviz.plot_posterior.html)
drammock commentedon Jul 11, 2023
@pllim there's also a very old issue #477 that has a couple other approaches.
SergejKr commentedon Oct 26, 2023
I use autosummary and would like to link to the source code rather than the automatically generated files. Any progress on this topic?
12rambau commentedon Oct 26, 2023
@Nauin2 whatever lib you use to generate API documentation (auto-api or autosummary) the mechanism is the same:
the extention build files on the fly in .rst that will then be interpreted at build time. I don't think I have access to source file at any step so I don't have any way to reach the github source file.
As a workaround you can still use the solution referenced in #477 by building a specific directive that will override the link using javascript.
What we are missing here is a good idea to capture the source file information whatever the VCS system (github, gitlab, gitea...).
SergejKr commentedon Oct 26, 2023
If I understand correctly, you need a link from the autogenerated .rst file to the source code, which could be anywhere in the repository.
In case of autosummary, it could be possible to alter the template with which the .rst files are generated and save the file directory within the .rst.
12rambau commentedon Oct 26, 2023
yes but it will be a special case solution, we won't be able to generalize it to all our userbase as we cannot edit the template from our end.
SergejKr commentedon Oct 26, 2023
Okay. Maybe another idea, again autosummary specific. The names of the autogenerated .rst files follow the dot notation of python. Using, e.g., the
getfilefunction of the inspect module the filepath to the source could be retrievable.12rambau commentedon Oct 26, 2023
If someone changes the api folder name or if the template is already altered by the user himself I will have no guarantee that the hack will work. This is a theme, we don't adapt files generated by other extensions it would be impossible to keep up with their release cycle.
what could be done is:
So it will force user to code something yes but it will be useful for all user whatever the api extention they are using. what do you think ?
SergejKr commentedon Oct 26, 2023
Sure, we can try this approach.
pllim commentedon Dec 23, 2023
Re: #1269 (comment)
@drammock , before I jump into the rabbit hole for this one, has there been any progress that would supersede the comment linked above?
p.s. Happy holidays!
drammock commentedon Dec 23, 2023
AFAIK no real progress. There is an open PR that allows to set the secondary sidebar templates on a per-page basis, which might make it easy to simply omit the source link on generated pages (using a glob pattern). But no progress on getting them to link to the actual source files
pllim commentedon Sep 20, 2024
Is there a way to disable the edit but only for generated pages? 🤔
vivodi commentedon Mar 21, 2025
Let me summarize: There are three methods currently available.