diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fb37000c0..168040b86a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### Documentation * Clarify the usage of "plot_joint" (#1001) +* Added the API link of function to examples (#1013) ## v0.6.1 (2019 Dec 28) diff --git a/doc/sphinxext/gallery_generator.py b/doc/sphinxext/gallery_generator.py index 391cee8879..0edfbe17fe 100644 --- a/doc/sphinxext/gallery_generator.py +++ b/doc/sphinxext/gallery_generator.py @@ -40,6 +40,7 @@ def execfile(filename, globals=None, locals=None): .. image:: {img_file} **Python source code:** :download:`[download source: {fname}]<{fname}>` +**API documentation:** {api_name} .. literalinclude:: {fname} :lines: {end_line}- @@ -54,6 +55,7 @@ def execfile(filename, globals=None, locals=None): :source-position: none **Python source code:** :download:`[download source: {fname}]<{fname}>` +**API documentation:** {api_name} .. literalinclude:: {fname} :lines: {end_line}- @@ -236,6 +238,18 @@ def thumbfilename(self): pngfile = self.modulename + "_thumb.png" return pngfile + @property + def apiname(self): + with open(op.join(self.target_dir, self.pyfilename), "r") as file: + regex = r"az\.(plot\_[a-z_]+)\(" + name = re.findall(regex, file.read()) + apitext = name[0] if name else "" + return ( + "`{apitext} <../../generated/arviz.{apitext}>`_".format(apitext=apitext) + if apitext + else "No API Documentation available" + ) + @property def sphinxtag(self): return self.modulename @@ -380,6 +394,7 @@ def main(app): fname=ex.pyfilename, absfname=op.join(target_dir, ex.pyfilename), img_file=ex.pngfilename, + api_name=ex.apiname, ) with open(op.join(target_dir, ex.rstfilename), "w") as f: f.write(output)