Skip to content

Commit

Permalink
last try (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
piskunow committed Nov 25, 2023
1 parent 8949110 commit 69fe2ee
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit 69fe2ee

Please sign in to comment.