Example Builder Plugin¶
This is a minimal example of a Hop3 build strategy plugin. It demonstrates the core concepts of plugin development.
What This Plugin Does¶
This plugin provides a simple build strategy that creates a Python virtualenv for applications. It's similar to the built-in Python builder but simplified for educational purposes.
Files¶
plugin.py- Plugin class with hook implementationbuilder.py- Build strategy implementationREADME.md- This file
How It Works¶
- Plugin Registration: The
ExamplePluginclass implements theget_builders()hook - Detection: The builder checks for
requirements.txtto detect Python apps - Build Process: Creates a virtualenv and installs dependencies
- Artifact: Returns information about the created virtualenv
Using This Example¶
As a Learning Tool¶
Study the code to understand:
- How to structure a plugin
- How to implement the Builder protocol
- How to register strategies via hooks
- How to return build artifacts
As a Template¶
Copy this structure for your own build strategy:
- Copy the directory
- Rename files and classes
- Modify
accept()to detect your app type - Implement your build logic in
build() - Update the plugin registration
Key Concepts Demonstrated¶
Protocol Implementation¶
The ExampleBuilder class implements the Builder protocol:
class Builder(Protocol):
name: str
context: DeploymentContext
def accept(self) -> bool: ...
def build(self) -> BuildArtifact: ...
Hook Implementation¶
The plugin uses @hookimpl to implement hooks:
Error Handling¶
Uses Abort from hop3.lib for user-facing errors:
Logging¶
Uses log() from hop3.lib for user feedback:
Testing¶
To test this plugin:
from pathlib import Path
from hop3.core.protocols import DeploymentContext
from builder import ExampleBuilder
# Create test context
context = DeploymentContext(
app_name="test",
source_path=Path("/path/to/app"),
app_config={}
)
# Instantiate builder
builder = ExampleBuilder(context)
# Test detection
assert builder.accept() is True
# Test build
artifact = builder.build()
assert artifact.kind == "virtualenv"
Next Steps¶
- See plugin-development.md for comprehensive guide
- See protocol-reference.md for protocol details
- Check real-world example:
hop3/builders/python.py