This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 0d4caa54ff [docs] Add 'Edit on GitHub' button (#13183)
0d4caa54ff is described below

commit 0d4caa54ff76537000c7ac981f44721186312bbe
Author: driazati <[email protected]>
AuthorDate: Tue Oct 25 07:10:47 2022 -0700

    [docs] Add 'Edit on GitHub' button (#13183)
    
    This changes the 'View Source' button on the top right of each doc page
    to a link that goes to a GitHub web editor for that docs page and
    automatically routes to the right source of truth, be it `.rst` or
    `.py`.
    
    Co-authored-by: driazati <[email protected]>
---
 docker/install/ubuntu_install_python_package.sh |  2 +-
 docs/conf.py                                    | 28 ++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/docker/install/ubuntu_install_python_package.sh 
b/docker/install/ubuntu_install_python_package.sh
index 9fee9d0142..757ad0228c 100755
--- a/docker/install/ubuntu_install_python_package.sh
+++ b/docker/install/ubuntu_install_python_package.sh
@@ -34,7 +34,7 @@ pip3 install --upgrade \
     Pillow==9.1.0 \
     psutil \
     pytest \
-    
git+https://github.com/tlc-pack/tlcpack-sphinx-addon.git@545450acaf0ee4e2932d8c5d9ab6e321d0bc86c8
 \
+    
git+https://github.com/tlc-pack/tlcpack-sphinx-addon.git@768ec1dce349fe4708f6ad68be1ebb3f3dabafa1
 \
     pytest-profiling \
     pytest-xdist \
     pytest-rerunfailures==10.2 \
diff --git a/docs/conf.py b/docs/conf.py
index 0767ccf82e..592d149c4c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -30,12 +30,10 @@
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 import gc
-import importlib.util
 import inspect
 import os
 from pathlib import Path
-import shlex
-import subprocess
+import re
 import sys
 
 import sphinx_gallery
@@ -420,6 +418,24 @@ header_dropdown = {
     ],
 }
 
+
+def fixup_tutorials(original_url: str) -> str:
+    if "docs/tutorial" in original_url:
+        # tutorials true source is in Python or .txt files, but Sphinx only 
sees
+        # the generated .rst files so this maps them back to the source
+        if original_url.endswith("index.rst"):
+            # for index pages, go to the README files
+            return re.sub(
+                r"docs/tutorial/(.*)index\.rst", 
"gallery/tutorial/\\1README.txt", original_url
+            )
+        else:
+            # otherwise for tutorials, redirect to python files
+            return re.sub(r"docs/tutorial/(.*)\.rst", 
"gallery/tutorial/\\1.py", original_url)
+    else:
+        # do nothing for normal non-tutorial .rst files
+        return original_url
+
+
 html_context = {
     "footer_copyright": footer_copyright,
     "footer_note": footer_note,
@@ -428,6 +444,12 @@ html_context = {
     "header_logo": header_logo,
     "header_logo_link": header_logo_link,
     "version_prefixes": ["main", "v0.8.0/", "v0.9.0/", "v0.10.0/"],
+    "display_github": True,
+    "github_user": "apache",
+    "github_repo": "tvm",
+    "github_version": "main/docs/",
+    "theme_vcs_pageview_mode": "edit",
+    "edit_link_hook_fn": fixup_tutorials,
 }
 
 # add additional overrides

Reply via email to