Metadata-Version: 2.5
Name: tsurara-plugin
Version: 0.1.2
Summary: Write tsurara plugins in Python
Project-URL: Repository, https://github.com/tsurara-openapi/tsurara
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: tsurara-client
Description-Content-Type: text/markdown

# tsurara-plugin

Write tsurara plugins in Python (docs/guide/plugins.md). A plugin module defines `plugin = define_plugin(...)` with any of the stages; tsurara runs it once per run with `python -m tsurara_plugin <module>`:

```yaml
plugins:
  - { module: ./plugin.py, runtime: [python, -m, tsurara_plugin] }
```

```python
from tsurara_plugin import ExtendInput, OutputFile, define_plugin


def extend(input: ExtendInput) -> list[OutputFile]:
    if input.manifest is None:
        return []
    return [
        OutputFile(path=f"functions/{op.operation_id}.txt", contents=f"{input.marker}\n{op.function.identifier}\n")
        for op in input.manifest.operations
        if op.function is not None
    ]


plugin = define_plugin(name="functions", extend=extend)
```

The types of the model, the manifest and the inputs (`tsurara_plugin.protocol`) are generated by tsurara from `spec/plugin-protocol.schema.json`. `PyFile` writes Python files with their imports, and `tsurara_plugin.testing.run_plugin` runs tsurara with a plugin for tests.
