def get_src_path(obj, src_root='tefla', append_base=True):
"""Creates a src path string with line info for use as markdown link.
"""
path = getsourcefile(obj)
if not src_root in path:
# this can happen with e.g.
# inlinefunc-wrapped functions
if hasattr(obj, "__module__"):
path = "%s.%s" % (obj.__module__, obj.__name__)
else:
path = obj.__name__
path = path.replace(".", "/")
try:
pre, post = path.rsplit(src_root + "/", 1)
except:
pre, post = '', ''
lineno = get_line_no(obj)
lineno = "" if lineno is None else "#L{}".format(lineno)
path = src_root + "/" + post + lineno
if append_base:
path = os.path.join(
'https://github.com/openagi/tefla/blob/master', path)
return path
评论列表
文章目录