Skip to main content
Ctrl+K

🖼️ Sphinx-Gallery

Site Navigation

  • User guide
  • Advanced
  • Demo galleries
  • Changelog

Site Navigation

  • User guide
  • Advanced
  • Demo galleries
  • Changelog

Section Navigation

  • Advanced usage
  • Frequently Asked Questions
  • Sphinx-Gallery Utilities
  • Sphinx-Gallery API Reference
    • sphinx_gallery.gen_gallery
    • sphinx_gallery.backreferences
    • sphinx_gallery.gen_rst
    • sphinx_gallery.scrapers
    • sphinx_gallery.py_source_parser
    • sphinx_gallery.docs_resolv
    • sphinx_gallery.notebook
    • sphinx_gallery.downloads
    • sphinx_gallery.sorting
    • sphinx_gallery.interactive_example
    • sphinx_gallery.directives
    • sphinx_gallery.utils.optipng
  • Advanced topics
  • Sphinx-Gallery API Reference
  • sphinx_gallery.backreferences

sphinx_gallery.backreferences#

Backreferences Generator.

Parses example file code in order to keep track of used functions.

Functions#

sphinx_gallery.backreferences.identify_names(script_blocks, ref_regex, global_variables=None, node='')[source]#

Build a codeobj summary by identifying and resolving used names.

Parameters:
  • script_blocks (list) – (label, content, line_number) List where each element is a tuple with the label (‘text’ or ‘code’), the corresponding content string of block and the leading line number.

  • ref_regex (str) – Regex to find references to python objects.

  • example_globals (Optional[Dict[str, Any]]) – Global variables for examples. Default=None

  • node (ast.Module or str) – The parsed node. Default=””.

Returns:

example_code_obj – OrderedDict with information about all code object references found in an example. OrderedDict contains the following keys:

  • example_code_obj[‘name’] : function or class name (str)

  • example_code_obj[‘module’] : module name (str)

  • example_code_obj[‘module_short’] : shortened module name (str)

  • example_code_obj[‘is_class’] : whether object is class (bool)

  • example_code_obj[‘is_explicit’]whether object is an explicit

    backreference (referred to by sphinx markup) (bool)

Return type:

OrderedDict[str, Any]

Examples using sphinx_gallery.backreferences.identify_names#

Identifying function names in a script

Identifying function names in a script

Classes#

class sphinx_gallery.backreferences.DummyClass[source]#

Dummy class for testing method resolution.

property prop#

Property.

run()[source]#

Do nothing.

class sphinx_gallery.backreferences.NameFinder(global_variables=None)[source]#

Finds the longest form of variable names and their imports in code.

Only retains names from imported modules.

get_mapping()[source]#

Map names used in code, using AST nodes, to their fully qualified names.

Returns:

options – List of tuples, each tuple containing the following information about an accessed_name:

accessed name : str, fully qualified name : str if it is a class attribute (i.e., property or method) : bool if it is a class : bool if it is an explicit backreference : bool (always false here)

Return type:

List[Tuple[str]]

visit_Attribute(node)[source]#

Add attributes, including their prefix, to accessed_names.

visit_Import(node, prefix='')[source]#

For ‘import’ add node names to imported_names.

visit_ImportFrom(node)[source]#

For ‘from import’ add node names to imported_names, incl module prefix.

visit_Name(node)[source]#

Add node id to accessed_names.

previous

sphinx_gallery.gen_gallery

next

sphinx_gallery.gen_rst

On this page
  • Functions
    • identify_names()
    • Examples using sphinx_gallery.backreferences.identify_names
  • Classes
    • DummyClass
      • DummyClass.prop
      • DummyClass.run()
    • NameFinder
      • NameFinder.get_mapping()
      • NameFinder.visit_Attribute()
      • NameFinder.visit_Import()
      • NameFinder.visit_ImportFrom()
      • NameFinder.visit_Name()

© Copyright 2014-2023, Sphinx-gallery developers.

Created using Sphinx 7.2.2.

Built with the PyData Sphinx Theme 0.13.3.