sphinx_gallery.py_source_parser

Parser for python source files

Functions

sphinx_gallery.py_source_parser.dedent(text)

Remove any common leading whitespace from every line in text.

This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.

Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines ” hello” and “thello” are considered to have no common leading whitespace. (This behaviour is new in Python 2.5; older versions of this module incorrectly expanded tabs before searching for common leading whitespace.)

sphinx_gallery.py_source_parser.get_docstring_and_rest(filename)

Separate filename content between docstring and the rest

Strongly inspired from ast.get_docstring.

Returns:
  • docstring (str) – docstring of filename
  • rest (str) – filename content without the docstring
sphinx_gallery.py_source_parser.split_code_and_text_blocks(source_file)

Return list with source file separated into code and text blocks.

Returns:blocks – List where each element is a tuple with the label (‘text’ or ‘code’), and content string of block.
Return type:list of (label, content)