spack.util.unparse package

spack.util.unparse.unparse(tree, py_ver_consistent=False)[source]

Submodules

spack.util.unparse.unparser module

Usage: unparse.py <path to source file>

class spack.util.unparse.unparser.Unparser(py_ver_consistent=False, _avoid_backslashes=False)[source]

Bases: object

Methods in this class recursively traverse an AST and output source code for the abstract syntax; original formatting is disregarded.

binop = {'Add': '+', 'BitAnd': '&', 'BitOr': '|', 'BitXor': '^', 'Div': '/', 'FloorDiv': '//', 'LShift': '<<', 'MatMult': '@', 'Mod': '%', 'Mult': '*', 'Pow': '**', 'RShift': '>>', 'Sub': '-'}
binop_precedence = {'%': 12, '&': 9, '*': 12, '**': 14, '+': 11, '-': 11, '/': 12, '//': 12, '<<': 10, '>>': 10, '@': 12, '^': 8, '|': 7}
binop_rassoc = frozenset({'**'})
block()[source]
boolop_precedence = {'and': 4, 'or': 3}
boolops = {'And': 'and', 'Or': 'or'}
cmpops = {'Eq': '==', 'Gt': '>', 'GtE': '>=', 'In': 'in', 'Is': 'is', 'IsNot': 'is not', 'Lt': '<', 'LtE': '<=', 'NotEq': '!=', 'NotIn': 'not in'}
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.

delimit_if(start, end, condition)[source]
dispatch(tree)[source]

Dispatcher function, dispatching tree type T to method _T.

fill(text='')[source]

Indent a piece of text, according to the current indentation level

get_precedence(node)[source]
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.

require_parens(precedence, node)[source]

Shortcut to adding precedence related parens

set_precedence(precedence, *nodes)[source]
unop = {'Invert': '~', 'Not': 'not', 'UAdd': '+', 'USub': '-'}
unop_precedence = {'+': 13, '-': 13, 'not': 5, '~': 13}
visit(tree, output_file)[source]

Traverse tree and write source code to output_file.

visit_AnnAssign(node)[source]
visit_Assert(node)[source]
visit_Assign(node)[source]
visit_AsyncFor(node)[source]
visit_AsyncFunctionDef(node)[source]
visit_AsyncWith(node)[source]
visit_Attribute(node)[source]
visit_AugAssign(node)[source]
visit_Await(node)[source]
visit_BinOp(node)[source]
visit_BoolOp(node)[source]
visit_Break(node)[source]
visit_Bytes(node)[source]
visit_Call(node)[source]
visit_ClassDef(node)[source]
visit_Compare(node)[source]
visit_Constant(node)[source]
visit_Continue(node)[source]
visit_Delete(node)[source]
visit_Dict(node)[source]
visit_DictComp(node)[source]
visit_Ellipsis(node)[source]
visit_ExceptHandler(node)[source]
visit_Expr(tree)[source]
visit_Expression(tree)[source]
visit_ExtSlice(node)[source]
visit_For(node)[source]
visit_FormattedValue(node)[source]
visit_FunctionDef(node)[source]
visit_GeneratorExp(node)[source]
visit_Global(node)[source]
visit_If(node)[source]
visit_IfExp(node)[source]
visit_Import(node)[source]
visit_ImportFrom(node)[source]
visit_Index(node)[source]
visit_Interactive(tree)[source]
visit_JoinedStr(node)[source]
visit_Lambda(node)[source]
visit_List(node)[source]
visit_ListComp(node)[source]
visit_Match(node)[source]
visit_MatchAs(node)[source]
visit_MatchClass(node)[source]
visit_MatchMapping(node)[source]
visit_MatchOr(node)[source]
visit_MatchSequence(node)[source]
visit_MatchSingleton(node)[source]
visit_MatchStar(node)[source]
visit_MatchValue(node)[source]
visit_Module(tree)[source]
visit_Name(node)[source]
visit_NameConstant(node)[source]
visit_NamedExpr(tree)[source]
visit_Nonlocal(node)[source]
visit_Num(node)[source]
visit_ParamSpec(node)[source]
visit_Pass(node)[source]
visit_Raise(node)[source]
visit_Return(node)[source]
visit_Set(node)[source]
visit_SetComp(node)[source]
visit_Slice(node)[source]
visit_Starred(node)[source]
visit_Str(tree)[source]
visit_Subscript(node)[source]
visit_Try(node)[source]
visit_Tuple(node)[source]
visit_TypeAlias(node)[source]
visit_TypeVar(node)[source]
visit_TypeVarTuple(node)[source]
visit_UnaryOp(node)[source]
visit_While(node)[source]
visit_With(node)[source]
visit_Yield(node)[source]
visit_YieldFrom(node)[source]
visit_alias(node)[source]
visit_arg(node)[source]
visit_arguments(node)[source]
visit_comprehension(node)[source]
visit_keyword(node)[source]
visit_match_case(node)[source]
visit_withitem(node)[source]
write(text)[source]

Append a piece of text to the current line.

spack.util.unparse.unparser.interleave(inter, f, seq)[source]

Call f on each item in seq, calling inter() in between.

spack.util.unparse.unparser.is_simple_tuple(slice_value)[source]
spack.util.unparse.unparser.nullcontext()[source]
spack.util.unparse.unparser.pnext(precedence)[source]