Backreferences Generator

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


sphinx_gallery.backreferences.escape(s, quote=True)

Replace special characters “&”, “<” and “>” to HTML-safe sequences. If the optional flag quote is true (the default), the quotation mark characters, both double quote (”) and single quote (‘) characters are also translated.

sphinx_gallery.backreferences.get_short_module_name(module_name, obj_name)

Get the shortest possible module name


Builds a codeobj summary by identifying and resolving used names

>>> code = '''
... from a.b import c
... import d as e
... print(c)
... e.HelloWorld().f.g
... '''
>>> for name, o in sorted(identify_names(code).items()):
...     print(name, o['name'], o['module'], o['module_short'])
c c a.b a.b
e.HelloWorld HelloWorld d d


class sphinx_gallery.backreferences.NameFinder

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

Only retains names from imported modules.