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 linkcode #39

Merged
merged 1 commit into from
Nov 25, 2023
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
28 changes: 15 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,25 @@ def linkcode_resolve(domain, info):
if module is None:
return None

filename = inspect.getsourcefile(module)
if filename is None:
return None
try:
filename = inspect.getsourcefile(module)
if filename is None:
return None

# Adjust the file path for the repository structure
package_dir = "src/kpm_tools"
rel_fn = os.path.relpath(filename, start=os.path.dirname(package_dir))
# Assuming your package is installed in 'site-packages'
# and the source is in 'src/kpm_tools' in the repo
src_path = filename.split("site-packages")[1]
rel_fn = "src" + src_path

obj = module
for part in info["fullname"].split("."):
obj = getattr(obj, part, None)
obj = module
for part in info["fullname"].split("."):
obj = getattr(obj, part, None)

if obj is None:
return None
if obj is None:
return None

try:
line = inspect.getsourcelines(obj)[1]
return f"{github_repo}/blob/{github_branch}/{rel_fn}#L{line}"
except Exception:
except Exception as e:
print(f"Error generating linkcode URL for {info['module']}: {e}")
return None
Loading