This page explains how the Rust core and Python interface interact in Angreal.
Angreal uses PyO3 to create Rust functions and types that can be called from Python. The main interface points include:
When you create a command in Python:
@angreal.command(name='hello', about='Say hello')
@angreal.argument(name='name', long='name', takes_value=True, help='Name to greet')
def hello(name='World'):
print(f"Hello, {name}!")
The following happens under the hood:
@command
decorator calls a Rust function that registers the command metadata@argument
decorator registers argument metadata with the commandCommand Registration
Template Context
Command Execution
Logging
The Rust-Python interface is implemented in several key files:
src/task.rs
- Command registration and executionsrc/builder/command_tree.rs
- Command-line argument processingsrc/lib.rs
- PyO3 module registrationEach Python function decorated with @command
is stored in a global registry in Rust, which is used to build the command-line interface and execute commands.