MCPcopy
hub / github.com/pydata/xarray / linkcode_resolve

Function linkcode_resolve

doc/conf.py:348–388  ·  view source on GitHub ↗

Determine the URL corresponding to Python object

(domain, info)

Source from the content-addressed store, hash-verified

346
347# based on numpy doc/source/conf.py
348def linkcode_resolve(domain, info):
349 """
350 Determine the URL corresponding to Python object
351 """
352 if domain != "py":
353 return None
354
355 modname = info["module"]
356 fullname = info["fullname"]
357
358 submod = sys.modules.get(modname)
359 if submod is None:
360 return None
361
362 obj = submod
363 for part in fullname.split("."):
364 try:
365 obj = getattr(obj, part)
366 except AttributeError:
367 return None
368
369 try:
370 fn = inspect.getsourcefile(inspect.unwrap(obj))
371 except TypeError:
372 fn = None
373 if not fn:
374 return None
375
376 try:
377 source, lineno = inspect.getsourcelines(obj)
378 except OSError:
379 lineno = None
380
381 if lineno:
382 linespec = f"#L{lineno}-L{lineno + len(source) - 1}"
383 else:
384 linespec = ""
385
386 fn = os.path.relpath(fn, start=os.path.dirname(xarray.__file__))
387
388 return f"https://github.com/pydata/xarray/blob/{source_ref}/xarray/{fn}{linespec}"
389
390
391def html_page_context(app, pagename, templatename, context, doctree):

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…