Rendering#
Render recipes with variant configurations to produce buildable outputs.
You can import the rendering classes from rattler_build:
VariantConfig#
Configuration for build variants.
Variants allow building the same recipe with different configurations, such as different Python versions, compilers, or other parameters.
This class provides a dict-like interface for managing variants.
Example
# Create from dict
config = VariantConfig({
"python": ["3.8", "3.9", "3.10"],
"numpy": ["1.21", "1.22"]
})
len(config.combinations()) # 3 * 2 = 6 combinations
# 6
# Dict-like access
print(config["python"])
# ['3.8', '3.9', '3.10']
# Get values
print(config.get_values("python"))
# ['3.8', '3.9', '3.10']
# Load from YAML file
config = VariantConfig.from_file("variant_config.yaml")
print(config.keys())
zip_keys
property
#
Get zip_keys - groups of keys that should be zipped together.
Zip keys ensure that certain variant keys are synchronized when creating combinations. For example, if python and numpy are zipped, then python=3.9 will always be paired with numpy=1.20, not with other numpy versions.
Returns:
| Type | Description |
|---|---|
list[list[str]] | None
|
List of groups (each group is a list of keys), or None if no zip keys are defined |
__init__ #
Create a new VariantConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variants
|
dict[str, list[Any]] | None
|
A dictionary mapping variant keys to value lists. If None, creates empty config. |
None
|
zip_keys
|
list[list[str]] | None
|
Optional list of groups (each group is a list of keys) that should be zipped together. Ensures that certain variant keys are synchronized. |
None
|
from_file
classmethod
#
Load VariantConfig from a YAML file (variants.yaml format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the variant configuration YAML file |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance |
from_file_with_context
classmethod
#
Load VariantConfig from a YAML file with a JinjaConfig context (variants.yaml format).
This allows evaluation of conditionals and templates in the variant file. The jinja_config provides platform information and other context needed for evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the variant configuration YAML file |
required |
jinja_config
|
JinjaConfig
|
JinjaConfig providing context for evaluation |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance |
from_files
classmethod
#
Load multiple VariantConfig files and merge them.
Files are merged in order, with later files taking precedence for overlapping keys. Zip keys from the last file that specifies them will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str | Path]
|
List of paths to variant configuration YAML files |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance with all files merged |
from_files_with_context
classmethod
#
Load multiple VariantConfig files with a JinjaConfig context and merge them.
Files are merged in order, with later files taking precedence.
Files named conda_build_config.yaml are loaded using the legacy
loader which supports # [selector] syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str | Path]
|
List of paths to variant configuration YAML files |
required |
jinja_config
|
JinjaConfig
|
JinjaConfig providing context for evaluation |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance with all files merged |
from_conda_build_config
classmethod
#
Load VariantConfig from a conda_build_config.yaml file.
This supports the legacy conda-build format with # [selector] syntax.
Selectors are evaluated using the provided JinjaConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the conda_build_config.yaml file |
required |
jinja_config
|
JinjaConfig
|
JinjaConfig providing context for selector evaluation |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance |
from_yaml
classmethod
#
Load VariantConfig from a YAML string (variants.yaml format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml
|
str
|
YAML string containing variant configuration |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance |
from_yaml_with_context
classmethod
#
Load VariantConfig from a YAML string with a JinjaConfig context (variants.yaml format).
This allows evaluation of conditionals and templates in the variant YAML. The jinja_config provides platform information and other context needed for evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml
|
str
|
YAML string containing variant configuration |
required |
jinja_config
|
JinjaConfig
|
JinjaConfig providing context for evaluation |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig instance |
merge #
Merge another VariantConfig into this one, returning a new VariantConfig.
Values from other take precedence for overlapping keys.
Zip keys from other replace those in self if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
VariantConfig
|
The VariantConfig to merge into this one |
required |
Returns:
| Type | Description |
|---|---|
VariantConfig
|
A new VariantConfig with merged values |
keys #
get_values #
Get values for a specific variant key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The variant key name |
required |
Returns:
| Type | Description |
|---|---|
list[Any] | None
|
List of values for the key, or None if key doesn't exist |
to_dict #
combinations #
Generate all combinations of variant values.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dictionaries, each representing one variant combination |
get #
Get values for a variant key with a default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The variant key name |
required |
default
|
list[Any] | None
|
Default value if key doesn't exist |
None
|
Returns:
| Type | Description |
|---|---|
list[Any] | None
|
List of values for the key, or default if key doesn't exist |
items #
values #
RenderConfig#
Configuration for rendering recipes with variants.
This class configures how recipes are rendered, including platform settings, experimental features, and additional Jinja context variables.
The recipe_path is not set here — it is automatically injected from
the :class:~rattler_build.stage0.Stage0Recipe during :meth:render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform
|
PlatformConfig | None
|
Platform configuration (target, build, host platforms, experimental flag) |
None
|
extra_context
|
dict[str, ContextValue] | None
|
Dictionary of extra context variables for Jinja rendering |
None
|
Example
get_context #
Get an extra context variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Variable name |
required |
Returns:
| Type | Description |
|---|---|
ContextValue | None
|
The variable value, or None if not found |
RenderedVariant#
Result of rendering a recipe with a specific variant combination.
Each RenderedVariant represents one specific variant of a recipe after all Jinja templates have been evaluated and variant values applied.
The :attr:recipe_path is carried over from the
:class:~rattler_build.stage0.Stage0Recipe that produced this variant
and is used automatically by :meth:run_build.
Attributes:
| Name | Type | Description |
|---|---|---|
variant |
dict[str, str]
|
The variant combination used (variable name -> value) |
recipe |
Stage1Recipe
|
The rendered Stage1 recipe |
hash_info |
HashInfo | None
|
Build string hash information |
pin_subpackages |
dict[str, PinSubpackageInfo]
|
Pin subpackage dependencies |
recipe_path |
Path
|
Path to the recipe file on disk |
Example
variant
property
#
Get the variant combination used for this render.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping variable names to their values |
recipe
property
#
Get the rendered Stage1 recipe.
Returns:
| Type | Description |
|---|---|
Stage1Recipe
|
The fully evaluated Stage1 recipe ready for building |
hash_info
property
#
Get hash info if available.
Returns:
| Type | Description |
|---|---|
HashInfo | None
|
HashInfo object with 'hash' and 'prefix' attributes, or None |
pin_subpackages
property
#
Get pin_subpackage information.
Returns:
| Type | Description |
|---|---|
dict[str, PinSubpackageInfo]
|
Dictionary mapping package names to PinSubpackageInfo objects |
run_build #
run_build(
tool_config=None,
output_dir=None,
channels=None,
progress_callback=None,
no_build_id=False,
package_format=None,
no_include_recipe=False,
exclude_newer=None,
)
Build this rendered variant.
This method builds a single rendered variant directly without needing
to go back through the Stage0 recipe. The recipe path is taken from
this variant automatically (set during :meth:Stage0Recipe.render).
For multi-output recipes, sibling variants are automatically known
from the :meth:~Stage0Recipe.render call and used to resolve
pin_subpackage dependencies between outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_config
|
ToolConfiguration | None
|
ToolConfiguration to use for the build. If None, uses defaults. |
None
|
output_dir
|
str | Path | None
|
Directory to store the built package.
Defaults to |
None
|
channels
|
list[str] | None
|
List of channels to use for resolving dependencies. Defaults to ["conda-forge"]. |
None
|
progress_callback
|
ProgressCallback | None
|
Optional progress callback for build events. |
None
|
no_build_id
|
bool
|
Don't include build ID in output directory. |
False
|
package_format
|
str | None
|
Package format ("conda" or "tar.bz2"). |
None
|
no_include_recipe
|
bool
|
Don't include recipe in the output package. |
False
|
exclude_newer
|
datetime | None
|
Exclude packages newer than this timestamp. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
BuildResult |
BuildResult
|
Information about the built package including paths, metadata, and timing. |
Example
from rattler_build import Stage0Recipe, VariantConfig
recipe = Stage0Recipe.from_yaml(yaml_string)
rendered = recipe.render(VariantConfig())
# Build just the first variant (output goes to <recipe_dir>/output)
result = rendered[0].run_build()
print(f"Built package: {result.packages[0]}")
# Multi-output recipes with pin_subpackage work automatically
for variant in rendered:
variant.run_build()
Supporting Types#
HashInfo#
Hash information for a rendered variant.
This class wraps the Rust HashInfo type and provides convenient access to hash information computed during recipe rendering.
Attributes:
| Name | Type | Description |
|---|---|---|
hash |
str
|
The hash string (first 7 letters of the sha1sum) |
prefix |
str
|
The hash prefix (e.g., 'py38' or 'np111') |
Example
PinSubpackageInfo#
Information about a pin_subpackage dependency.
This class wraps the Rust PinSubpackageInfo type and provides information about packages pinned via the pin_subpackage() Jinja function.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the pinned subpackage |
version |
str
|
The version of the pinned subpackage |
build_string |
str | None
|
The build string of the pinned subpackage (if known) |
exact |
bool
|
Whether this is an exact pin |