Skip to content

Commit

Permalink
Rename and refactor rendering module
Browse files Browse the repository at this point in the history
Renamed `rendering.py` to `expressions.py`, and refactored to load the environment dynamically rather than using a static instance. Adjusted project to require Python 3.12 and updated dependencies accordingly, including the addition of `asttokens` and `icecream`.
  • Loading branch information
coordt committed Nov 3, 2024
1 parent fc042a2 commit 9137a77
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Tools for rendering templates and template strings."""
"""Render template expressions."""

from typing import MutableMapping, Optional, Union

from minijinja import Environment

ENV = Environment()
from project_forge.rendering.environment import load_environment


def render_bool_expression(expression: Union[str, bool], context: Optional[MutableMapping] = None) -> bool:
Expand Down Expand Up @@ -32,4 +30,6 @@ def render_bool_expression(expression: Union[str, bool], context: Optional[Mutab
def render_expression(expression: str, context: Optional[MutableMapping] = None) -> str:
"""Render a template expression."""
context = context or {}
return ENV.render_str(expression, **context).strip()
env = load_environment()
template = env.from_string(expression)
return template.render(**context).strip()
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ classifiers = [
keywords = ["project_forge"]
dynamic = ["version"]
license = { file = "LICENSE" }
requires-python = ">=3.9"
requires-python = ">=3.12"
dependencies = [
"environs>=9.3.5",
"pydantic>=2.8.2",
"minijinja>=2.2.0",
"jinja2>=3.1.0",
"pyyaml>=6.0.2",
"tomlkit>=0.13.2",
"click>=8.1.7",
Expand All @@ -43,6 +43,7 @@ Changelog = "https://github.com/callowayproject/project-forge/CHANGELOG.md"
dev = [
"bump-my-version",
"generate-changelog>=0.7.6",
"icecream",
"uv",
]
test = [
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from pytest import param
from project_forge.rendering import render_bool_expression
from project_forge.rendering.expressions import render_bool_expression


class TestRenderBoolExpression:
Expand Down
Loading

0 comments on commit 9137a77

Please sign in to comment.