From 79bd9535475c4a96424e92ab4b35c4e1bbb2897f Mon Sep 17 00:00:00 2001 From: John Zielke Date: Thu, 16 May 2024 15:19:51 +0000 Subject: [PATCH 1/3] Fix doc source links for read the docs Signed-off-by: John Zielke --- docs/source/conf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 782b585c9f..674ead37ac 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -168,7 +168,11 @@ def setup(app): # -- Linkcode configuration -------------------------------------------------- DEFAULT_REF = "dev" -if os.environ.get("GITHUB_REF_TYPE", "branch") == "tag": +if git_ref := os.environ.get("READTHEDOCS_GIT_IDENTIFIER", None): + # When building on ReadTheDocs, link to the specific commit + # https://docs.readthedocs.io/en/stable/reference/environment-variables.html#envvar-READTHEDOCS_GIT_IDENTIFIER + git_ref = git_ref +elif os.environ.get("GITHUB_REF_TYPE", "branch") == "tag": # When building a tag, link to the tag itself git_ref = os.environ.get("GITHUB_REF", DEFAULT_REF) else: @@ -179,7 +183,7 @@ def setup(app): base_code_url = f"https://github.com/{repository}/blob/{git_ref}" MODULE_ROOT_FOLDER = "monai" - +repo_root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) # Adjusted from https://github.com/python-websockets/websockets/blob/main/docs/conf.py def linkcode_resolve(domain, info): @@ -208,7 +212,7 @@ def linkcode_resolve(domain, info): except TypeError: # e.g. object is a typing.Union return None - file = os.path.relpath(file, os.path.abspath("..")) + file = os.path.relpath(file, repo_root_path) if not file.startswith(MODULE_ROOT_FOLDER): # e.g. object is a typing.NewType return None From c48c4671aef2d47c173ec98ef65a6b8cf95587e3 Mon Sep 17 00:00:00 2001 From: John Zielke Date: Thu, 16 May 2024 15:59:01 +0000 Subject: [PATCH 2/3] Fix format Signed-off-by: John Zielke --- docs/source/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index 674ead37ac..b7a5fcb660 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -185,6 +185,7 @@ def setup(app): MODULE_ROOT_FOLDER = "monai" repo_root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + # Adjusted from https://github.com/python-websockets/websockets/blob/main/docs/conf.py def linkcode_resolve(domain, info): if domain != "py": From 83669186fd6f5df326533e3006ae25a708de7a5d Mon Sep 17 00:00:00 2001 From: John Zielke Date: Fri, 17 May 2024 00:55:20 +0000 Subject: [PATCH 3/3] Address comments Signed-off-by: John Zielke --- docs/source/conf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index b7a5fcb660..b7da022cff 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -168,10 +168,11 @@ def setup(app): # -- Linkcode configuration -------------------------------------------------- DEFAULT_REF = "dev" -if git_ref := os.environ.get("READTHEDOCS_GIT_IDENTIFIER", None): +read_the_docs_ref = os.environ.get("READTHEDOCS_GIT_IDENTIFIER", None) +if read_the_docs_ref: # When building on ReadTheDocs, link to the specific commit # https://docs.readthedocs.io/en/stable/reference/environment-variables.html#envvar-READTHEDOCS_GIT_IDENTIFIER - git_ref = git_ref + git_ref = read_the_docs_ref elif os.environ.get("GITHUB_REF_TYPE", "branch") == "tag": # When building a tag, link to the tag itself git_ref = os.environ.get("GITHUB_REF", DEFAULT_REF)