From a2f19367c0bad29245c0c51ce122d1c766e532b8 Mon Sep 17 00:00:00 2001 From: Hung Do Date: Thu, 24 Jul 2025 17:58:11 -0400 Subject: [PATCH 1/3] Added suggested fix from GitHub Issue --- doc/_templates/sourcelink.html | 15 ++++++++++++ doc/source/conf.py | 10 ++++++-- doc/sphinxext/edit_on_github.py | 42 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 doc/_templates/sourcelink.html create mode 100644 doc/sphinxext/edit_on_github.py diff --git a/doc/_templates/sourcelink.html b/doc/_templates/sourcelink.html new file mode 100644 index 0000000000000..751f08ab31922 --- /dev/null +++ b/doc/_templates/sourcelink.html @@ -0,0 +1,15 @@ +{%- if show_source and has_source and sourcename %} +

{{ _('This Page') }}

+ +{%- endif %} diff --git a/doc/source/conf.py b/doc/source/conf.py index f222a228531ff..5e51dbf5c6cdf 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -44,6 +44,9 @@ ] ) +# Edit on GitHub links +sys.path.insert(0, os.path.abspath('_ext')) + # -- General configuration ----------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be @@ -69,6 +72,7 @@ "sphinx.ext.mathjax", "sphinx.ext.todo", "nbsphinx", + 'edit_on_github', ] exclude_patterns = [ @@ -114,8 +118,6 @@ ): exclude_patterns.append(rel_fname) elif single_doc and rel_fname != pattern: - if "\\" in rel_fname: - rel_fname = rel_fname.replace("\\", "/") exclude_patterns.append(rel_fname) with open(os.path.join(source_path, "index.rst.template"), encoding="utf-8") as f: @@ -149,6 +151,10 @@ # https://sphinx-toggleprompt.readthedocs.io/en/stable/#offset toggleprompt_offset_right = 35 +# Configure the "Edit on GitHub links for Sphinx" extention +edit_on_github_project = 'username/reponame' +edit_on_github_branch = 'master' + # Add any paths that contain templates here, relative to this directory. templates_path = ["../_templates"] diff --git a/doc/sphinxext/edit_on_github.py b/doc/sphinxext/edit_on_github.py new file mode 100644 index 0000000000000..357ca7d7ee046 --- /dev/null +++ b/doc/sphinxext/edit_on_github.py @@ -0,0 +1,42 @@ +""" +Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the +sidebar. + +Loosely based on https://github.com/astropy/astropy/pull/347 +""" + +import os +import warnings + + +__licence__ = 'BSD (3 clause)' + + +def get_github_url(app, view, path): + return 'https://github.com/{project}/{view}/{branch}/{path}'.format( + project=app.config.edit_on_github_project, + view=view, + branch=app.config.edit_on_github_branch, + path=path) + + +def html_page_context(app, pagename, templatename, context, doctree): + if templatename != 'page.html': + return + + if not app.config.edit_on_github_project: + warnings.warn("edit_on_github_project not specified") + return + + path = os.path.relpath(doctree.get('source'), app.builder.srcdir) + show_url = get_github_url(app, 'blob', path) + edit_url = get_github_url(app, 'edit', path) + + context['show_on_github_url'] = show_url + context['edit_on_github_url'] = edit_url + + +def setup(app): + app.add_config_value('edit_on_github_project', '', True) + app.add_config_value('edit_on_github_branch', 'master', True) + app.connect('html-page-context', html_page_context) From 6dab33e3f0487cef12e62fb78b507a29449d2139 Mon Sep 17 00:00:00 2001 From: Hung Do Date: Tue, 29 Jul 2025 17:46:30 -0400 Subject: [PATCH 2/3] Fixed show and edit links --- doc/source/conf.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 5e51dbf5c6cdf..a36c4c8b24a64 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -44,9 +44,6 @@ ] ) -# Edit on GitHub links -sys.path.insert(0, os.path.abspath('_ext')) - # -- General configuration ----------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be @@ -152,8 +149,8 @@ toggleprompt_offset_right = 35 # Configure the "Edit on GitHub links for Sphinx" extention -edit_on_github_project = 'username/reponame' -edit_on_github_branch = 'master' +edit_on_github_project = 'pandas-dev/pandas' +edit_on_github_branch = 'main/doc/source' # Add any paths that contain templates here, relative to this directory. templates_path = ["../_templates"] From 482d09feb88ae75289ff7b2c1e7912357f234a31 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Jul 2025 22:39:05 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/source/conf.py | 6 +++--- doc/sphinxext/edit_on_github.py | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index a36c4c8b24a64..0a65786ce9ab6 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -69,7 +69,7 @@ "sphinx.ext.mathjax", "sphinx.ext.todo", "nbsphinx", - 'edit_on_github', + "edit_on_github", ] exclude_patterns = [ @@ -149,8 +149,8 @@ toggleprompt_offset_right = 35 # Configure the "Edit on GitHub links for Sphinx" extention -edit_on_github_project = 'pandas-dev/pandas' -edit_on_github_branch = 'main/doc/source' +edit_on_github_project = "pandas-dev/pandas" +edit_on_github_branch = "main/doc/source" # Add any paths that contain templates here, relative to this directory. templates_path = ["../_templates"] diff --git a/doc/sphinxext/edit_on_github.py b/doc/sphinxext/edit_on_github.py index 357ca7d7ee046..e8d5bbf7d8849 100644 --- a/doc/sphinxext/edit_on_github.py +++ b/doc/sphinxext/edit_on_github.py @@ -8,35 +8,35 @@ import os import warnings - -__licence__ = 'BSD (3 clause)' +__licence__ = "BSD (3 clause)" def get_github_url(app, view, path): - return 'https://github.com/{project}/{view}/{branch}/{path}'.format( + return "https://github.com/{project}/{view}/{branch}/{path}".format( project=app.config.edit_on_github_project, view=view, branch=app.config.edit_on_github_branch, - path=path) + path=path, + ) def html_page_context(app, pagename, templatename, context, doctree): - if templatename != 'page.html': + if templatename != "page.html": return if not app.config.edit_on_github_project: warnings.warn("edit_on_github_project not specified") return - path = os.path.relpath(doctree.get('source'), app.builder.srcdir) - show_url = get_github_url(app, 'blob', path) - edit_url = get_github_url(app, 'edit', path) + path = os.path.relpath(doctree.get("source"), app.builder.srcdir) + show_url = get_github_url(app, "blob", path) + edit_url = get_github_url(app, "edit", path) - context['show_on_github_url'] = show_url - context['edit_on_github_url'] = edit_url + context["show_on_github_url"] = show_url + context["edit_on_github_url"] = edit_url def setup(app): - app.add_config_value('edit_on_github_project', '', True) - app.add_config_value('edit_on_github_branch', 'master', True) - app.connect('html-page-context', html_page_context) + app.add_config_value("edit_on_github_project", "", True) + app.add_config_value("edit_on_github_branch", "master", True) + app.connect("html-page-context", html_page_context)