def get_src_path(self, obj, append_base=True):
"""Creates a src path string with line info for use as markdown link.
"""
path = getsourcefile(obj)
if self.src_root not 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(".", "/")
pre, post = path.rsplit(self.src_root + "/", 1)
lineno = self.get_line_no(obj)
lineno = "" if lineno is None else "#L{}".format(lineno)
path = self.src_root + "/" + post + lineno
if append_base:
path = os.path.join(self.github_link, path)
return path
评论列表
文章目录