Get a link to the line number a module/class/function is defined at.

    Parameters
    ----------
    thing : function or class
        Thing to get the link for
    source_location : str
        GitHub url of the source code

    Returns
    -------
    str
        String with link to the file & line number, or empty string if it
        couldn't be found

def get_source_link(thing, source_location):
    """
    Get a link to the line number a module/class/function is defined at.

    Parameters
    ----------
    thing : function or class
        Thing to get the link for
    source_location : str
        GitHub url of the source code

    Returns
    -------
    str
        String with link to the file & line number, or empty string if it
        couldn't be found
    """
    try:
        lineno = get_line(thing)
        try:
            owner_module = inspect.getmodule(thing)
            assert owner_module is not None
        except (TypeError, AssertionError):
            owner_module = inspect.getmodule(thing.fget)

        thing_file = "/".join(owner_module.__name__.split("."))
        if owner_module.__file__.endswith("__init__.py"):
            thing_file += "/__init__.py"
        else:
            thing_file += ".py"
        return (
            f"Source: [{escape(thing_file)}]({source_location}/{thing_file}#L{lineno})"
            + "\n\n"
        )
    except Exception as e:
        # print("Failed to find source file.")
        # print(e)
        # print(lineno)
        # print(thing)
        # print(owner_module)
        # print(thing_file)
        # print(source_location)
        pass
    return ""