11from __future__ import annotations
22
3- from typing import Any , TypedDict
3+ from typing import TypedDict
44
55import jinja2
6- import yaml
6+ from jinja2 . sandbox import SandboxedEnvironment
77
8- from conda_forge_tick .jinja .filters import _bool , _split , _version_to_build_string
9- from conda_forge_tick .jinja .objects import (
8+ from conda_forge_tick .update_recipe .v2 .jinja .filters import (
9+ _bool ,
10+ _split ,
11+ _version_to_build_string ,
12+ )
13+ from conda_forge_tick .update_recipe .v2 .jinja .objects import (
1014 _stub_compatible_pin ,
1115 _stub_is_linux ,
1216 _stub_is_unix ,
1519 _stub_subpackage_pin ,
1620 _StubEnv ,
1721)
18- from conda_forge_tick .jinja .utils import _MissingUndefined
19- from conda_forge_tick .loader import load_yaml
22+ from conda_forge_tick .update_recipe .v2 .jinja .utils import _MissingUndefined
23+
24+ # from conda_forge_tick.update_recipe.v2.loader import load_yaml
2025
2126
2227class RecipeWithContext (TypedDict , total = False ):
2328 context : dict [str , str ]
2429
2530
26- def jinja_env () -> jinja2 . Environment :
31+ def jinja_env () -> SandboxedEnvironment :
2732 """
2833 Create a `rattler-build` specific Jinja2 environment with modified syntax.
2934 Target platform, build platform, and mpi are set to linux-64 by default.
3035 """
31- env = jinja2 . sandbox . SandboxedEnvironment (
36+ env = SandboxedEnvironment (
3237 variable_start_string = "${{" ,
3338 variable_end_string = "}}" ,
3439 trim_blocks = True ,
@@ -71,7 +76,9 @@ def jinja_env() -> jinja2.Environment:
7176 return env
7277
7378
74- def load_recipe_context (context : dict [str , str ], jinja_env : jinja2 .Environment ) -> dict [str , str ]:
79+ def load_recipe_context (
80+ context : dict [str , str ], jinja_env : jinja2 .Environment
81+ ) -> dict [str , str ]:
7582 """
7683 Load all string values from the context dictionary as Jinja2 templates.
7784 Use linux-64 as default target_platform, build_platform, and mpi.
@@ -87,30 +94,30 @@ def load_recipe_context(context: dict[str, str], jinja_env: jinja2.Environment)
8794 return context
8895
8996
90- def render_recipe_with_context (recipe_content : RecipeWithContext ) -> dict [str , Any ]:
91- """
92- Render the recipe using known values from context section.
93- Unknown values are not evaluated and are kept as it is.
94- Target platform, build platform, and mpi are set to linux-64 by default.
95-
96- Examples:
97- ---
98- ```python
99- >>> from pathlib import Path
100- >>> from conda_forge_tick.loader import load_yaml
101- >>> recipe_content = load_yaml((Path().resolve() / "tests" / "data" / "eval_recipe_using_context.yaml").read_text())
102- >>> evaluated_context = render_recipe_with_context(recipe_content)
103- >>> assert "my_value-${{ not_present_value }}" == evaluated_context["build"]["string"]
104- >>>
105- ```
106- """
107- env = jinja_env ()
108- context = recipe_content .get ("context" , {})
109- # render out the context section and retrieve dictionary
110- context_variables = load_recipe_context (context , env )
111-
112- # render the rest of the document with the values from the context
113- # and keep undefined expressions _as is_.
114- template = env .from_string (yaml .dump (recipe_content ))
115- rendered_content = template .render (context_variables )
116- return load_yaml (rendered_content )
97+ # def render_recipe_with_context(recipe_content: RecipeWithContext) -> dict[str, Any]:
98+ # """
99+ # Render the recipe using known values from context section.
100+ # Unknown values are not evaluated and are kept as it is.
101+ # Target platform, build platform, and mpi are set to linux-64 by default.
102+
103+ # Examples:
104+ # ---
105+ # ```python
106+ # >>> from pathlib import Path
107+ # >>> from conda_forge_tick.loader import load_yaml
108+ # >>> recipe_content = load_yaml((Path().resolve() / "tests" / "data" / "eval_recipe_using_context.yaml").read_text())
109+ # >>> evaluated_context = render_recipe_with_context(recipe_content)
110+ # >>> assert "my_value-${{ not_present_value }}" == evaluated_context["build"]["string"]
111+ # >>>
112+ # ```
113+ # """
114+ # env = jinja_env()
115+ # context = recipe_content.get("context", {})
116+ # # render out the context section and retrieve dictionary
117+ # context_variables = load_recipe_context(context, env)
118+
119+ # # render the rest of the document with the values from the context
120+ # # and keep undefined expressions _as is_.
121+ # template = env.from_string(yaml.dump(recipe_content))
122+ # rendered_content = template.render(context_variables)
123+ # return load_yaml(rendered_content)
0 commit comments