Recipe#
Recipe classes for parsing and working with conda recipes.
rattler-build uses a two-stage recipe system:
- Stage0 - Parsed YAML recipes before Jinja template evaluation
- Stage1 - Fully evaluated recipes ready for building
You can import the recipe classes from rattler_build:
Stage0 - Parsed Recipes#
Stage0Recipe#
Bases: ABC
A parsed conda recipe (stage0).
This is an abstract base class. Use from_yaml(), from_file(), or from_dict()
to create concrete instances (SingleOutputRecipe or MultiOutputRecipe).
Example
from_yaml
classmethod
#
Parse a recipe from a YAML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml
|
str
|
The YAML recipe content. |
required |
recipe_dir
|
Path | str | None
|
Directory to write the recipe file into. When
|
None
|
Returns:
| Type | Description |
|---|---|
Stage0Recipe
|
SingleOutputRecipe or MultiOutputRecipe depending on the recipe type. |
from_file
classmethod
#
Parse a recipe from a YAML file.
The file path is used as the recipe path directly — no copy is made.
Returns:
| Type | Description |
|---|---|
Stage0Recipe
|
SingleOutputRecipe or MultiOutputRecipe depending on the recipe type. |
from_dict
classmethod
#
Create a recipe from a Python dictionary.
This method validates the dictionary structure and provides detailed error messages if the structure is invalid or types don't match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_dict
|
dict[str, Any]
|
Dictionary containing recipe data (must match recipe schema). |
required |
recipe_dir
|
Path | str | None
|
Directory to write the recipe file into. When
|
None
|
Returns:
| Type | Description |
|---|---|
Stage0Recipe
|
SingleOutputRecipe or MultiOutputRecipe depending on the recipe type. |
Raises:
| Type | Description |
|---|---|
PyRecipeParseError
|
If the dictionary structure is invalid or types don't match. |
as_single_output #
Get as a single output recipe.
Raises:
| Type | Description |
|---|---|
TypeError
|
If this is not a single-output recipe. |
as_multi_output #
Get as a multi output recipe.
Raises:
| Type | Description |
|---|---|
TypeError
|
If this is not a multi-output recipe. |
render #
Render this recipe with variant configuration.
This method takes this Stage0 recipe and evaluates all Jinja templates with different variant combinations to produce ready-to-build Stage1 recipes.
The recipe's :attr:recipe_path is automatically injected into the
render configuration so that Jinja functions like include() and
file_name() can resolve relative paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant_config
|
VariantConfig | None
|
Optional VariantConfig to use. If None, creates an empty config. |
None
|
render_config
|
RenderConfig | None
|
Optional RenderConfig to use. If None, uses default config. |
None
|
Returns:
| Type | Description |
|---|---|
list[RenderedVariant]
|
List of RenderedVariant objects (one for each variant combination) |
run_build #
run_build(
variant_config=None,
tool_config=None,
output_dir=None,
channels=None,
progress_callback=None,
no_build_id=False,
package_format=None,
no_include_recipe=False,
debug=False,
exclude_newer=None,
)
Build this recipe.
This method renders the recipe with variants and then builds the rendered
outputs. The :attr:recipe_path is used automatically for directory
setup and recipe inclusion in the package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant_config
|
VariantConfig | None
|
Optional VariantConfig to use for building variants. |
None
|
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 packages.
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
|
debug
|
bool
|
Enable debug mode. |
False
|
exclude_newer
|
datetime | None
|
Exclude packages newer than this timestamp. |
None
|
Returns:
| Type | Description |
|---|---|
list[BuildResult]
|
list[BuildResult]: List of build results, one per variant built. |
Example
recipe = Stage0Recipe.from_yaml(yaml_string)
# Build with default output dir (<recipe_dir>/output)
results = recipe.run_build()
for result in results:
print(f"Built {result.name} {result.version}")
print(f"Package at: {result.packages[0]}")
# Or with custom tool configuration
from rattler_build import ToolConfiguration
config = ToolConfiguration(keep_build=True, test_strategy="native")
results = recipe.run_build(tool_config=config, output_dir="./output")
SingleOutputRecipe#
MultiOutputRecipe#
Stage1 - Evaluated Recipes#
Stage1Recipe#
A fully evaluated conda recipe (stage1), ready for building.
This represents the recipe after all Jinja templates have been evaluated and all conditionals resolved.
Example
inherits_from
property
#
Get inheritance information if this output inherits from a cache.
Supporting Types#
Stage0 Types#
Requirements at stage0.
run_constraints
property
#
Get run-time constraints (list of matchspecs or templates).
About metadata at stage0.
license_family
property
#
Get the license family (deprecated, may be a template or None).