Skip to content

Commit 83991b9

Browse files
authored
Fix the linkcode function to resolve paths relative to the morpheus root (#2323)
* This code was broken when we refactored code into `morpheus_dfp` and `morpheus_llm` packages and put them under the `python` subdir. ## By Submitting this PR I confirm: - I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md). - When the PR is ready for review, new or existing tests cover these changes. - When the PR is ready for review, the documentation is up to date with these changes. Authors: - David Gardner (https://github.com/dagardner-nv) Approvers: - Anuradha Karuppiah (https://github.com/AnuradhaKaruppiah) URL: #2323
1 parent 3bbd5e8 commit 83991b9

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@
351351

352352
# The following is used by sphinx.ext.linkcode to provide links to github
353353
linkcode_resolve = make_linkcode_resolve(
354-
'morpheus', 'https://github.com/nv-morpheus/Morpheus'
355-
'/blob/{revision}/'
356-
'{package}/{path}#L{lineno}')
354+
morpheus_root=morpheus_root,
355+
package='morpheus',
356+
url_fmt='https://github.com/nv-morpheus/Morpheus/blob/{revision}/{path}#L{lineno}')
357357

358358
# Set the default role for interpreted code (anything surrounded in `single
359359
# backticks`) to be a python object. See

docs/source/sphinxext/github_link.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,7 +59,7 @@ def _get_git_revision():
5959
return revision.decode('utf-8')
6060

6161

62-
def _linkcode_resolve(domain, info, package, url_fmt, revision):
62+
def _linkcode_resolve(domain, info, *, package, url_fmt, revision, morpheus_root):
6363
"""Determine a link to online source for a class/method/function
6464
6565
This is called by sphinx.ext.linkcode
@@ -139,7 +139,7 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):
139139
fn = os.path.abspath(os.path.join("..", "python", fn))
140140

141141
# Convert to relative from module root
142-
fn = os.path.relpath(fn, start=os.path.dirname(__import__(package).__file__))
142+
fn = os.path.relpath(fn, start=morpheus_root)
143143

144144
# Get the line number if we need it. (Can work without it)
145145
if (lineno is None):
@@ -152,10 +152,13 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision):
152152
lineno = obj.__code__.co_firstlineno
153153
else:
154154
lineno = ''
155-
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
156155

156+
url = url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
157157

158-
def make_linkcode_resolve(package, url_fmt):
158+
return url
159+
160+
161+
def make_linkcode_resolve(*, morpheus_root: str, package: str, url_fmt: str):
159162
"""Returns a linkcode_resolve function for the given URL format
160163
161164
revision is a git commit reference (hash or name)
@@ -167,4 +170,4 @@ def make_linkcode_resolve(package, url_fmt):
167170
'{path}#L{lineno}')
168171
"""
169172
revision = _get_git_revision()
170-
return partial(_linkcode_resolve, revision=revision, package=package, url_fmt=url_fmt)
173+
return partial(_linkcode_resolve, morpheus_root=morpheus_root, revision=revision, package=package, url_fmt=url_fmt)

0 commit comments

Comments
 (0)