maya.utils.converter.codegen ============================ .. py:module:: maya.utils.converter.codegen .. autoapi-nested-parse:: Code generation utilities for maya.cmds output. This module handles the generation of valid Python code that uses maya.cmds from the converted AST representations. Classes ------- .. autoapisummary:: maya.utils.converter.codegen.CodeBuilder Functions --------- .. autoapisummary:: maya.utils.converter.codegen.format_connectattr_call maya.utils.converter.codegen.format_getattr_call maya.utils.converter.codegen.format_setattr_call maya.utils.converter.codegen.generate_cmds_import maya.utils.converter.codegen.generate_header_comment maya.utils.converter.codegen.wrap_in_function Module Contents --------------- .. py:class:: CodeBuilder(indent_size: int = 4) Utility for building well-formatted Python code output. Handles indentation, line continuations, and comment insertion to produce readable, diff-friendly output. .. py:method:: add_blank_line() -> CodeBuilder Add a blank line. Returns: Self for method chaining. .. py:method:: add_comment(comment: str) -> CodeBuilder Add a comment line. Args: comment: The comment text (without #). Returns: Self for method chaining. .. py:method:: add_import(module: str, items: Optional[List[str]] = None) -> CodeBuilder Add an import statement. Args: module: Module to import from. items: Specific items to import (for 'from' imports). Returns: Self for method chaining. .. py:method:: add_line(line: str) -> CodeBuilder Add a line of code with current indentation. Args: line: The line of code to add. Returns: Self for method chaining. .. py:method:: build() -> str Build the final code string. Returns: The generated code as a string. .. py:method:: dedent() -> CodeBuilder Decrease indentation level. Returns: Self for method chaining. .. py:method:: indent() -> CodeBuilder Increase indentation level. Returns: Self for method chaining. .. py:attribute:: indent_size :value: 4 .. py:function:: format_connectattr_call(src_node: str, src_attr: str, dst_node: str, dst_attr: str, force: bool = True, use_fstring: bool = True) -> str Format a cmds.connectAttr call. Args: src_node: Source node expression. src_attr: Source attribute name. dst_node: Destination node expression. dst_attr: Destination attribute name. force: Whether to force the connection. use_fstring: Whether to use f-strings for paths. Returns: Formatted connectAttr call. .. py:function:: format_getattr_call(node_expr: str, attr_name: str, use_fstring: bool = True) -> str Format a cmds.getAttr call. Args: node_expr: Expression for the node. attr_name: Attribute name. use_fstring: Whether to use f-strings for the path. Returns: Formatted getAttr call. .. py:function:: format_setattr_call(node_expr: str, attr_name: str, value: str, use_fstring: bool = True) -> str Format a cmds.setAttr call. Args: node_expr: Expression for the node. attr_name: Attribute name. value: Value expression. use_fstring: Whether to use f-strings for the path. Returns: Formatted setAttr call. .. py:function:: generate_cmds_import() -> str Generate the standard maya.cmds import statement. Returns: Import statement string. .. py:function:: generate_header_comment(original_info: Optional[str] = None, warnings: Optional[List[str]] = None) -> str Generate a header comment for converted code. Args: original_info: Information about the original source. warnings: List of warnings to include. Returns: Header comment string. .. py:function:: wrap_in_function(code: str, function_name: str = 'converted_code', docstring: Optional[str] = None) -> str Wrap converted code in a function definition. Args: code: The code to wrap. function_name: Name for the function. docstring: Optional docstring. Returns: The wrapped code.