TofuPilotTofuPilot

Python

Run Python functions as test phases with full framework access.

You can run any Python function using the python parameter.

Let's start by creating a Python file in a new phases/ directory:

procedure.yaml
check_device.py

Then add a new phase referencing this module:

main:
  - name: Test Functionality
    python: phases.check_device
def check_device():
    # Your code here

TofuPilot will manage your Python Environment, run your function, and provide access to framework features through Function Parameters.

File

You can specify which Python file to execute using dot notation. Paths are resolved relative to your procedure.yaml file.

For example, for this file tree:

procedure.yaml
foo.py
bar.py
baz.py

You can reference these files with:

main:
  - name: Foo
    python: phases.foo
  - name: Bar
    python: phases.nested.bar
  - name: Baz
    python: shared.baz

Function

You can specify which function to call using colon syntax: module:function.

TofuPilot defaults to the last component of the path as the function name.

main:
  - name: Calibration
    python: calibrate # Calls calibrate() function by default

  - name: Custom Function
    python: calibrate:run_calibration # Calls run_calibration() instead
def calibrate():
    # Default function - called by first phase

def run_calibration():
    # Custom function - called by second phase

Environment

Overview

TofuPilot automatically manages Python virtual environments and runs your code in isolation, ensuring consistent behavior across development and production.

As soon as you add a Python phase to your procedure, TofuPilot automatically:

  1. Looks for an existing virtual environment (.venv or venv) in your procedure directory
  2. If found: Uses it as-is
  3. If not found:
    • Creates a pyproject.toml file if one doesn't exist (Python's standard project manifest defining Python version and dependencies)
    • Creates a new .venv directory with the specified Python version (defaults to 3.11)
    • Installs all dependencies listed in pyproject.toml
  4. Syncs dependencies if pyproject.toml changes

Dependencies

Edit pyproject.toml in your procedure directory to manage dependencies:

[project]
name = "my-procedure"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "numpy>=1.24.0",
    "pandas>=2.0.0",
]

TofuPilot will automatically install these dependencies when you run your procedure.

Under the hood, TofuPilot uses UV, a Python package manager faster than pip, with full support for the PEP 508 dependency specification.

For advanced use cases, you can configure private registries, local packages, Git dependencies, and platform-specific requirements directly in your pyproject.toml:

Function Parameters

TofuPilot automatically injects parameters based on your function signature. You can refer to each framework feature's documentation for Python function parameters usage.

How is this guide?