Overview
Custom builders let you create any type of build artifact: executables, documentation, packages, Docker images, or anything else. Builders extend theBuilderConfigFile base class and implement the create_artifacts() method.
Creating a Custom Builder
1. Choose a Location
Place your builder inpyrig/rig/builders/ for automatic discovery:
pyrig build.
2. Extend BuilderConfigFile
Create a class that extendsBuilderConfigFile:
3. Implement create_artifacts()
Thecreate_artifacts() method is where your build logic lives:
4. Build
Run the build command:Example Builders
Documentation Builder
Create a builder that archives documentation:dist/myapp-docs-Linux.zip
Wheel Builder
Create a builder that builds Python wheels:dist/myapp-0.1.0-py3-none-any-Linux.whl
Docker Image Builder
Create a builder that builds and exports Docker images:dist/myapp-Linux.tar
Source Archive Builder
Create a builder that creates source archives:dist/myapp-src-Linux.tar.gz
Advanced Customization
Custom Output Directory
Overridedist_dir_name() to change the output directory:
artifacts/ instead of dist/
Disable Platform Suffixes
Overrideplatform_specific_name() to disable platform suffixes:
dist/myapp.zip instead of dist/myapp-Linux.zip
Multiple Artifacts
Create multiple artifacts in a single builder:dist/myapp-docs-Linux.zipdist/myapp-src-Linux.tar.gzdist/myapp-0.1.0-py3-none-any-Linux.whl
Conditional Builds
Only create artifacts under certain conditions:Using Helper Methods
Use the helper methods provided byBuilderConfigFile:
Testing Custom Builders
Use theconfig_file_factory fixture to test builders:
Complete Example
Here’s a complete custom builder with all features:releases/:
myapp-Linux(executable)myapp-docs-Linux.zip(documentation)myapp-src-Linux.tar.gz(source code)myapp-Linux.sha256(checksums)
Best Practices
1. Use Temporary Directory
Always create artifacts intemp_artifacts_dir, not directly in dist/:
2. Use Helper Methods
Use the provided helper methods instead of hardcoding paths:3. Handle Errors
Handle build errors gracefully:4. Document Your Builder
Add clear docstrings:5. Test Your Builder
Always write tests for custom builders:Next Steps
PyInstaller Integration
Learn about PyInstaller integration
Testing
Learn how to test your builders