def linkcode_resolve(domain, info): """ Determine the URL corresponding to Python object """ if domain != 'py': return None modname = info['module'] fullname = info['fullname'] submod = sys.modules.get(modname) if submod is None: return None obj = submod for part in fullname.split('.'): try: obj = getattr(obj, part) except Exception: return None try: fn = inspect.getsourcefile(obj) except Exception: fn = None if not fn: try: fn = inspect.getsourcefile(sys.modules[obj.__module__]) except Exception: fn = None if not fn: return None try: source, lineno = inspect.getsourcelines(obj) except Exception: lineno = None if lineno: linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) else: linespec = "" startdir = os.path.abspath(os.path.join(dirname(scipy.__file__), '..')) fn = relpath(fn, start=startdir).replace(os.path.sep, '/') if fn.startswith('scipy/'): m = re.match(r'^.*dev0\+([a-f0-9]+)$', scipy.__version__) if m: return "https://github.com/scipy/scipy/blob/%s/%s%s" % ( m.group(1), fn, linespec) elif 'dev' in scipy.__version__: return "https://github.com/scipy/scipy/blob/master/%s%s" % ( fn, linespec) else: return "https://github.com/scipy/scipy/blob/v%s/%s%s" % ( scipy.__version__, fn, linespec) else: return None
def linkcode_resolve(domain, info): """ Determine the URL corresponding to Python object """ if domain != 'py': return None modname = info['module'] fullname = info['fullname'] submod = sys.modules.get(modname) if submod is None: return None obj = submod for part in fullname.split('.'): try: obj = getattr(obj, part) except Exception: return None # Use the original function object if it is wrapped. obj = getattr(obj, "__wrapped__", obj) # SciPy's distributions are instances of *_gen. Point to this # class since it contains the implementation of all the methods. if isinstance(obj, (rv_generic, multi_rv_generic)): obj = obj.__class__ try: fn = inspect.getsourcefile(obj) except Exception: fn = None if not fn: try: fn = inspect.getsourcefile(sys.modules[obj.__module__]) except Exception: fn = None if not fn: return None try: source, lineno = inspect.getsourcelines(obj) except Exception: lineno = None if lineno: linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) else: linespec = "" startdir = os.path.abspath(os.path.join(dirname(scipy.__file__), '..')) fn = relpath(fn, start=startdir).replace(os.path.sep, '/') if fn.startswith('scipy/'): m = re.match(r'^.*dev0\+([a-f0-9]+)$', scipy.__version__) if m: return "https://github.com/scipy/scipy/blob/%s/%s%s" % ( m.group(1), fn, linespec) elif 'dev' in scipy.__version__: return "https://github.com/scipy/scipy/blob/main/%s%s" % (fn, linespec) else: return "https://github.com/scipy/scipy/blob/v%s/%s%s" % ( scipy.__version__, fn, linespec) else: return None