Skip to content

Commit 230c51c

Browse files
aaronvgcursoragent
andauthored
Migrate jinja to minijinja2 (#2025)
The `jinja` and `jinja-runtime` crates were migrated to use MiniJinja 2.x, addressing API changes and rendering differences. Key changes include: * **Dependency Update**: MiniJinja was upgraded from 1.0.16 to 2.10.2 in `engine/Cargo.toml` and `engine/baml-lib/jinja/Cargo.toml`, with the "serde" feature added to resolve deprecation warnings. * **Object Trait Migration**: * `StructObject` was replaced with the new `Object` trait across `baml_value_to_jinja_value.rs`, `render_context.rs`, and `minijinja.rs`. * The `call` method signature was updated to `self: <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Migrate from MiniJinja 1.x to 2.x, updating dependencies and adapting to API changes, including replacing `StructObject` with `Object` trait and updating method signatures. > > - **Dependency Update**: > - Upgrade `minijinja` from 1.0.16 to 2.10.2 in `Cargo.toml` files. > - Add `serde` feature to `minijinja` to resolve deprecation warnings. > - **Object Trait Migration**: > - Replace `StructObject` with `Object` trait in `minijinja.rs`, `baml_value_to_jinja_value.rs`, and `render_context.rs`. > - Update `call` method signatures to use `self: &Arc<Self>`. > - Implement `render` method for `Object` trait in `minijinja.rs`, `baml_value_to_jinja_value.rs`, and `output_format/mod.rs`. > - **Code Adjustments**: > - Handle `CallArg` variants in `expr.rs` and `pretty_print.rs`. > - Update `parse_as_function_call` and `tracker_visit_expr` to handle new `minijinja` AST structures. > - Modify `evaluate_type` tests to align with new syntax in `test_stmt.rs`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 0c832f2. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 1b64d85 commit 230c51c

23 files changed

Lines changed: 399 additions & 218 deletions

File tree

engine/Cargo.lock

Lines changed: 27 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ baml-lsp-types = { path = "baml-lsp-types" }
7474
jsonish = { path = "baml-lib/jsonish" }
7575
log = "0.4.20"
7676
# TODO: disable imports, etc
77-
minijinja = { version = "1.0.16", default-features = false, features = [
77+
minijinja = { version = "2.10.2", default-features = false, features = [
7878
"macros",
7979
"builtins",
8080
"debug",
@@ -87,6 +87,7 @@ minijinja = { version = "1.0.16", default-features = false, features = [
8787
"custom_syntax",
8888
"internal_debug",
8989
"deserialization",
90+
"serde",
9091
# We don't want to use these features:
9192
# multi_template
9293
# loader

engine/baml-lib/baml-types/src/minijinja.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{BamlMedia, BamlValue};
22
use std::fmt;
3+
use std::sync::Arc;
34

45
/// A wrapper around a jinja expression. The inner `String` should not contain
56
/// the interpolation brackets `{{ }}`; it should be a bare expression like
@@ -77,7 +78,7 @@ impl std::fmt::Debug for MinijinjaBamlMedia {
7778

7879
impl minijinja::value::Object for MinijinjaBamlMedia {
7980
fn call(
80-
&self,
81+
self: &Arc<Self>,
8182
_state: &minijinja::State<'_, '_>,
8283
args: &[minijinja::value::Value],
8384
) -> Result<minijinja::value::Value, minijinja::Error> {
@@ -86,4 +87,8 @@ impl minijinja::value::Object for MinijinjaBamlMedia {
8687
format!("BamlImage has no callable attribute '{args:#?}'"),
8788
))
8889
}
90+
91+
fn render(self: &Arc<Self>, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92+
std::fmt::Display::fmt(self, f)
93+
}
8994
}

0 commit comments

Comments
 (0)