Skip to content

Commit

Permalink
undo merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Aug 4, 2024
1 parent 2a85ad7 commit ba16541
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pytest = ">=8.2.2,<9"
syrupy = ">=4.6.1,<5"

[feature.tests.tasks]
tests = "pytest --doctest-modules ./tests"
tests = "pytest --doctest-modules"
snapshot_update = "pytest --snapshot-update tests"

[feature.lint.dependencies]
Expand Down
39 changes: 0 additions & 39 deletions src/rattler_build_conda_compat/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any

import jinja2
import yaml

from rattler_build_conda_compat.conditional_list import visit_conditional_list
Expand Down Expand Up @@ -165,41 +164,3 @@ def load_all_tests(content: dict[str, Any]) -> list[dict]:
evaluated_tests.extend(list(visit_conditional_list(section)))

return evaluated_tests


def jinja_env() -> jinja2.Environment:
# Create a custom Jinja2 environment with modified syntax
return jinja2.Environment(
variable_start_string="${{",
variable_end_string="}}",
trim_blocks=True,
lstrip_blocks=True,
autoescape=True,
)


def render_context(context: dict[str, str]) -> dict[str, str]:
env = jinja_env()
# Process each key-value pair in the dictionary
for key, value in context.items():
# If the value is a string, render it as a template
if isinstance(value, str):
template = env.from_string(value)
rendered_value = template.render(context)
context[key] = rendered_value

return context


def eval_jinja(content: dict[str, Any]) -> dict[str, Any]:
context = content.get("context")
# render the context
rendered_context = render_context(context)

# render the rest of the document with the values from the context
# and keep undefined expressions _as is_.
env = jinja_env()
template = env.from_string(yaml.dump(content))
rendered_content = template.render(rendered_context)

return load_yaml(rendered_content)
16 changes: 0 additions & 16 deletions tests/__snapshots__/test_rattler_render.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@
'target_platform': 'linux-64',
})
# ---
# name: test_render_context
dict({
'build': dict({
'string': 'foo-bla',
}),
'context': dict({
'name': 'foo',
'name_version': 'foo-bla',
'version': 'bla',
}),
'package': dict({
'name': 'foo',
'version': 'bla',
}),
})
# ---
# name: test_render_recipe
list([
dict({
Expand Down
5 changes: 3 additions & 2 deletions tests/test_rattler_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import os
from pathlib import Path

from typing import Any
from typing import TYPE_CHECKING, Any

from rattler_build_conda_compat.loader import parse_recipe_config_file
from rattler_build_conda_compat.render import MetaData, render

if TYPE_CHECKING:
from pathlib import Path


def test_render_recipe(python_recipe: Path, unix_namespace: dict[str, Any], snapshot) -> None:
variants = parse_recipe_config_file(str(python_recipe / "variants.yaml"), unix_namespace)
Expand Down

0 comments on commit ba16541

Please sign in to comment.