Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc source links for read the docs #7779

Merged
merged 4 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading