diff --git a/docs/conf.py b/docs/conf.py index b6ce2da..68ed925 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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