Skip to content

Commit 7429e2a

Browse files
johnzielkeKumoLiu
andauthored
Fix doc source links for read the docs (#7779)
Fixes the current docs build. Currently no [source] links are shown anymore. It seems like read the docs uses a different working directory, therefore breaking the source links. It also will not have the correct git tag referenced. This should fix both of these issues. If there is a way to test if this fix works without merging to dev, let me know. ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: John Zielke <[email protected]> Co-authored-by: YunLiu <[email protected]>
1 parent 5e9ac1b commit 7429e2a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

docs/source/conf.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def generate_apidocs(*args):
140140
"github_repo": "MONAI",
141141
"github_version": "dev",
142142
"doc_path": "docs/source",
143-
"conf_py_path": "/docs/",
143+
"conf_py_path": "/docs/source",
144144
"VERSION": version,
145145
}
146146
html_scaled_image_link = False
@@ -167,11 +167,24 @@ def setup(app):
167167

168168

169169
# -- Linkcode configuration --------------------------------------------------
170+
DEFAULT_REF = "dev"
171+
read_the_docs_ref = os.environ.get("READTHEDOCS_GIT_IDENTIFIER", None)
172+
if read_the_docs_ref:
173+
# When building on ReadTheDocs, link to the specific commit
174+
# https://docs.readthedocs.io/en/stable/reference/environment-variables.html#envvar-READTHEDOCS_GIT_IDENTIFIER
175+
git_ref = read_the_docs_ref
176+
elif os.environ.get("GITHUB_REF_TYPE", "branch") == "tag":
177+
# When building a tag, link to the tag itself
178+
git_ref = os.environ.get("GITHUB_REF", DEFAULT_REF)
179+
else:
180+
git_ref = os.environ.get("GITHUB_SHA", DEFAULT_REF)
181+
170182
DEFAULT_REPOSITORY = "Project-MONAI/MONAI"
171183
repository = os.environ.get("GITHUB_REPOSITORY", DEFAULT_REPOSITORY)
172184

173-
base_code_url = f"https://github.com/{repository}/blob/{version}"
185+
base_code_url = f"https://github.com/{repository}/blob/{git_ref}"
174186
MODULE_ROOT_FOLDER = "monai"
187+
repo_root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
175188

176189

177190
# Adjusted from https://github.com/python-websockets/websockets/blob/main/docs/conf.py
@@ -201,7 +214,7 @@ def linkcode_resolve(domain, info):
201214
except TypeError:
202215
# e.g. object is a typing.Union
203216
return None
204-
file = os.path.relpath(file, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
217+
file = os.path.relpath(file, repo_root_path)
205218
if not file.startswith(MODULE_ROOT_FOLDER):
206219
# e.g. object is a typing.NewType
207220
return None

0 commit comments

Comments
 (0)