Tools for Source Code Generation¶
- class pytools.codegen.CodeGenerator¶
Language-agnostic functionality for source code generation.
- extend(sub_generator: pytools.codegen.CodeGenerator) None ¶
- class pytools.codegen.Indentation(generator: pytools.codegen.CodeGenerator)¶
A context manager for indentation for use with
CodeGenerator
.- generator¶
- pytools.codegen.remove_common_indentation(code: str, require_leading_newline: bool = True)¶
Remove leading indentation from one or more lines of code.
Removes an amount of indentation equal to the indentation level of the first nonempty line in code.
- Parameters
code – Input string.
require_leading_newline – If True, only remove indentation if code starts with
\n
.
- Returns
A copy of code stripped of leading common indentation.