Skip to content

Commit

Permalink
Fix doc source links for read the docs (#7779)
Browse files Browse the repository at this point in the history
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 <j.l.zielke@gmail.com>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
  • Loading branch information
johnzielke and KumoLiu authored May 17, 2024
1 parent 5e9ac1b commit 7429e2a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def generate_apidocs(*args):
"github_repo": "MONAI",
"github_version": "dev",
"doc_path": "docs/source",
"conf_py_path": "/docs/",
"conf_py_path": "/docs/source",
"VERSION": version,
}
html_scaled_image_link = False
Expand All @@ -167,11 +167,24 @@ def setup(app):


# -- Linkcode configuration --------------------------------------------------
DEFAULT_REF = "dev"
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 = 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)
else:
git_ref = os.environ.get("GITHUB_SHA", DEFAULT_REF)

DEFAULT_REPOSITORY = "Project-MONAI/MONAI"
repository = os.environ.get("GITHUB_REPOSITORY", DEFAULT_REPOSITORY)

base_code_url = f"https://github.com/{repository}/blob/{version}"
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
Expand Down Expand Up @@ -201,7 +214,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(os.path.join(os.path.dirname(__file__), "..", "..")))
file = os.path.relpath(file, repo_root_path)
if not file.startswith(MODULE_ROOT_FOLDER):
# e.g. object is a typing.NewType
return None
Expand Down

0 comments on commit 7429e2a

Please sign in to comment.