A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://sphinx-gallery.github.io/stable/auto_examples/plot_6_function_identifier.html below:

Identifying function names in a script — Sphinx-Gallery 0.19.0-git documentation

Note

Go to the end to download the full example code. or to run this example in your browser via JupyterLite or Binder

Identifying function names in a script#

This demonstrates how Sphinx-Gallery identifies when

  1. a function/method/attribute/object is used or class instantiated in a code block

  2. a function/method/attribute/object/class is referred to using sphinx markup in a text block.

Sphinx-Gallery examines both the executed code itself, as well as the text blocks (such as this one, or the one below) for these references and identifies the module they belong to. This means that by writing numpy.sin and numpy.exp here, they will be identified even though they are not used in the code. This is useful in particular when functions return classes (meaning it is not explicitly instantiated) – if you add them to the documented blocks of examples that use them, they will be added to backreferences.

This functionality is used to add documentation hyperlinks to your code (Add intersphinx links to your examples) and for mini-gallery creation (Add mini-galleries for API documentation).

In the code block above, we use the internal function identify_names to obtain all identified names from this file and their full resolved import path. We then plot this below, where the identified names functions are on the left and the full resolved import path is on the right.

fontsize = 12.5
figheight = 3 * len(names) * fontsize / 72
fig, ax = plt.subplots(figsize=(7.5, figheight))
ax.set_visible(False)

for i, (name, obj) in enumerate(names.items(), 1):
    fig.text(
        0.48,
        1 - i / (len(names) + 1),
        name,
        ha="right",
        va="center",
        size=fontsize,
        transform=fig.transFigure,
        bbox=dict(boxstyle="square", fc="w", ec="k"),
    )
    fig.text(
        0.52,
        1 - i / (len(names) + 1),
        obj[0]["module"],
        ha="left",
        va="center",
        size=fontsize,
        transform=fig.transFigure,
        bbox=dict(boxstyle="larrow,pad=0.1", fc="w", ec="k"),
    )

plt.show()

Total running time of the script: (0 minutes 0.776 seconds)

Estimated memory usage: 193 MB

Gallery generated by Sphinx-Gallery


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4