maya.utils.converter.engine_reverse¶
Core conversion engine for maya.cmds → tik.maya transformation.
This module orchestrates the reverse conversion process: 1. Parse source code into AST 2. Analyze and track maya.cmds usage patterns 3. Apply reverse conversion rules 4. Generate tik.maya output code 5. Produce conversion report
This engine mirrors the structure of engine.py but operates in the reverse direction: lifting cmds into tik.maya.
Classes¶
Tracks state during AST traversal and reverse conversion. |
|
Main converter class for maya.cmds → tik.maya transformation. |
Functions¶
|
Convenience function to convert maya.cmds code to tik.maya. |
|
Extract source code for an AST node. |
|
Parse Python source code into AST and lines. |
Module Contents¶
- class ReverseConversionState¶
Tracks state during AST traversal and reverse conversion.
Maintains information about: - Variable types (inferred from cmds calls) - Import statements - Converted nodes (to avoid double-processing) - Node name to variable mappings
- get_variable_type(name: str) str | None¶
Get the tracked type for a variable.
- Args:
name: Variable name.
- Returns:
The type name if tracked, None otherwise.
- is_converted(node: ast.AST) bool¶
Check if an AST node has been converted.
- Args:
node: The AST node to check.
- Returns:
True if already converted.
- mark_converted(node: ast.AST) None¶
Mark an AST node as converted.
- Args:
node: The AST node that was converted.
- track_node_variable(node_name: str, var_name: str) None¶
Track a node name to variable mapping.
- Args:
node_name: The Maya node name string. var_name: The Python variable name.
- track_variable(name: str, type_name: str) None¶
Track a variable’s inferred type.
- Args:
name: Variable name. type_name: The inferred type (e.g., “Transform”).
- cmds_imports_found: bool = False¶
- converted_nodes: Set[int]¶
- imports: Dict[str, str]¶
- node_variables: Dict[str, str]¶
- variable_types: Dict[str, str]¶
- class ReverseConverter(rules: List[maya.utils.converter.rules_reverse.ReverseConversionRule] | None = None, add_imports: bool = True, add_header: bool = True, preserve_comments: bool = True)¶
Main converter class for maya.cmds → tik.maya transformation.
The converter performs semantic lifting of maya.cmds code into idiomatic tik.maya expressions. It compresses explicit cmds calls into the equivalent tik.maya API.
- Usage:
converter = ReverseConverter() result = converter.convert(source_code) print(result.converted_code) print(result.summary())
- convert(source_code: str) maya.utils.converter.report.ConversionReport¶
Convert maya.cmds source code to tik.maya.
- Args:
source_code: Python source code using maya.cmds.
- Returns:
ConversionReport with converted code and metadata.
- add_header = True¶
- add_imports = True¶
- preserve_comments = True¶
- rules¶
- convert_to_tik(source_code: str, add_imports: bool = True, add_header: bool = True) maya.utils.converter.report.ConversionReport¶
Convenience function to convert maya.cmds code to tik.maya.
- Args:
source_code: Python source code using maya.cmds. add_imports: Whether to add tik.maya import. add_header: Whether to add header comment.
- Returns:
ConversionReport with results.
- get_node_source(node: ast.AST, source_lines: List[str]) str¶
Extract source code for an AST node.
- Args:
node: AST node with line/column info. source_lines: List of source code lines.
- Returns:
The source code corresponding to the node.
- parse_source(source_code: str)¶
Parse Python source code into AST and lines.
- Args:
source_code: Python source code string.
- Returns:
Tuple of (AST module, list of source lines).
- Raises:
SyntaxError: If the source code has syntax errors.