spack.util.unparse package¶
Submodules¶
spack.util.unparse.unparser module¶
Usage: unparse.py <path to source file>
- class spack.util.unparse.unparser.NodeVisitor[source]¶
Bases:
objectA node visitor base class that walks the abstract syntax tree and calls a visitor function for every node found. This function may return a value which is forwarded by the visit method.
This class is meant to be subclassed, with the subclass adding visitor methods.
Per default the visitor functions for the nodes are
'visit_'+ class name of the node. So a TryFinally node visit function would be visit_TryFinally. This behavior can be changed by overriding the visit method. If no visitor function exists for a node (return value None) the generic_visit visitor is used instead.Don’t use the NodeVisitor if you want to apply changes to nodes during traversing. For this a special visitor exists (NodeTransformer) that allows modifications.
- class spack.util.unparse.unparser.Unparser(py_ver_consistent=False, _avoid_backslashes=False)[source]¶
Bases:
NodeVisitorMethods in this class recursively traverse an AST and output source code for the abstract syntax; original formatting is disregarded.
- binop¶
- binop_precedence¶
- binop_rassoc¶
- block(*, extra=None)[source]¶
A context manager for preparing the source for blocks. It adds the character’:’, increases the indentation on enter and decreases the indentation on exit. If extra is given, it will be directly appended after the colon character.
- boolop_precedence¶
- boolops¶
- cmpops¶
- delimit(start, end)[source]¶
A context manager for preparing the source for expressions. It adds start to the buffer and enters, after exit it adds end.
- fill(text='')[source]¶
Indent a piece of text and append it, according to the current indentation level
- get_raw_docstring(node)[source]¶
If a docstring node is found in the body of the node parameter, return that docstring node, None otherwise.
Logic mirrored from
_PyAST_GetDocString.
- items_view(traverser, items)[source]¶
Traverse and separate the given items with a comma and append it to the buffer. If items is a single item sequence, a trailing comma will be added.
- unop¶
- unop_precedence¶
- spack.util.unparse.unparser.is_non_empty_non_star_tuple(slice_value)[source]¶
True for (1, 2), False for () and (1, *b)