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)
评论列表
文章目录