What are Builders?
Builders are specialized configuration file handlers that create build artifacts (executables, documentation, packages, etc.) rather than configuration files. The builder system provides a framework for creating platform-specific artifacts with organized output and automatic cleanup.How Builders Work
Builders extend theBuilderConfigFile base class and repurpose the configuration file interface for build operations:
load()- Returns existing artifacts from the output directorydump()- Triggers the build processcreate_file()- Creates the output directory structurecreate_artifacts()- Defines the build logic (implemented by subclasses)
Build Lifecycle
When you runpyrig build, each builder goes through this lifecycle:
- Create temporary directory - A temp directory is created for intermediate files
- Call
create_artifacts()- Subclass implements the build logic here - Collect artifacts - All files in the temp directory are collected
- Rename with platform suffixes - Artifacts get names like
myapp-Linux.exe,myapp-Windows.exe - Move to output directory - Artifacts are moved to
dist/(or custom directory) - Clean up - Temporary directory is automatically removed
BuilderConfigFile Base Class
TheBuilderConfigFile class provides the foundation for all builders:
Key Methods
Required Implementation
Create artifacts in the temporary directory. All files created here will be automatically collected, renamed with platform suffixes, and moved to the final output directory.Args:
temp_artifacts_dir(Path): Temporary directory where artifacts should be created
Available Methods
Get the name of the artifacts directory. Default is
"dist", but can be overridden.Returns: str - Name of the artifacts directoryGet the application name from
pyproject.toml.Returns: str - Project nameGet the absolute path to the project root directory.Returns: Path - Project root path
Get the absolute path to the
main.py entry point.Returns: Path - Path to main.pyGet the absolute path to the resources directory.Returns: Path - Path to resources directory
Get the absolute path to the source package directory.Returns: Path - Path to source package
Platform-Specific Naming
Builders automatically add platform-specific suffixes to artifacts:- Linux:
myapp-Linux.exe - Windows:
myapp-Windows.exe - macOS:
myapp-Darwin.exe
Example: Simple Builder
Here’s a complete example of a basic builder:pyrig/rig/builders/documentation.py and run:
dist/myapp-docs-Linux.zip (or Windows/Darwin variant).
Custom Output Directory
Overridedist_dir_name() to change the output directory:
Automatic Discovery
Builders are automatically discovered when placed inpyrig/rig/builders/. You can also place them in the equivalent location in any package that depends on pyrig.
Next Steps
PyInstaller Integration
Create standalone executables with PyInstaller
Custom Builders
Learn how to create your own custom builders