conf.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:cupy 作者: cupy 项目源码 文件源码
def linkcode_resolve(domain, info):
    if domain != 'py' or not info['module']:
        return None

    rtd_version = os.environ.get('READTHEDOCS_VERSION')
    if rtd_version == 'latest':
        tag = 'master'
    else:
        tag = 'v{}'.format(__version__)

    # Import the object from module path
    obj = _import_object_from_name(info['module'], info['fullname'])

    # If it's not defined in the internal module, return None.
    mod = inspect.getmodule(obj)
    if mod is None:
        return None
    if not (mod.__name__ == 'cupy' or mod.__name__.startswith('cupy.')):
        return None

    # Get the source file name and line number at which obj is defined.
    try:
        filename = inspect.getsourcefile(obj)
    except TypeError:
        # obj is not a module, class, function, ..etc.
        return None

    # inspect can return None for cython objects
    if filename is None:
        return None

    # Get the source line number
    _, linenum = inspect.getsourcelines(obj)
    assert isinstance(linenum, six.integer_types)

    filename = os.path.realpath(filename)
    relpath = _get_source_relative_path(filename)

    return 'https://github.com/cupy/cupy/blob/{}/{}#L{}'.format(
        tag, relpath, linenum)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号