Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2")
# https://registry.bazel.build/modules/cel-cpp
bazel_dep(name = "cel-cpp", version = "0.14.0", repo_name = "com_google_cel_cpp")

# 03/30/2026
_CEL_CPP_COMMIT = "5a3463337cf2a9b90b53833af2bbc1f35da90d64"
# 04/07/2025
_CEL_CPP_COMMIT = "7022451780867bd9c173956f5793b5dfb600928e"

_CEL_CPP_SHA256 = "299be398d1495340eb92da31f9a0667e1351479752e8a567ac31c385e4aea73c"
_CEL_CPP_SHA256 = "d1b9b2c2e9745826c1c8540a49f972ea4b93dffd5878c6a67756a2627b0119ef"

archive_override(
module_name = "cel-cpp",
Expand Down
9 changes: 8 additions & 1 deletion cel_expr_python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pybind_extension(
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:span",
"@com_google_cel_cpp//checker:type_checker_builder",
"@com_google_cel_cpp//checker:type_checker_builder_factory",
"@com_google_cel_cpp//checker:validation_result",
"@com_google_cel_cpp//common:ast",
"@com_google_cel_cpp//common:ast_proto",
Expand All @@ -78,8 +79,13 @@ pybind_extension(
"@com_google_cel_cpp//compiler",
"@com_google_cel_cpp//env",
"@com_google_cel_cpp//env:config",
"@com_google_cel_cpp//env:env_runtime",
"@com_google_cel_cpp//env:env_std_extensions",
"@com_google_cel_cpp//env:env_yaml",
"@com_google_cel_cpp//env:runtime_std_extensions",
"@com_google_cel_cpp//extensions/protobuf:runtime_adapter",
"@com_google_cel_cpp//parser",
"@com_google_cel_cpp//parser:options",
"@com_google_cel_cpp//parser:parser_interface",
"@com_google_cel_cpp//runtime",
"@com_google_cel_cpp//runtime:activation",
Expand All @@ -88,7 +94,7 @@ pybind_extension(
"@com_google_cel_cpp//runtime:reference_resolver",
"@com_google_cel_cpp//runtime:runtime_builder",
"@com_google_cel_cpp//runtime:runtime_options",
"@com_google_cel_cpp//runtime:standard_runtime_builder_factory",
"@com_google_cel_cpp//validator",
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
"@com_google_protobuf//:protobuf",
Expand Down Expand Up @@ -135,6 +141,7 @@ py_test(
srcs = ["cel_env_test.py"],
deps = [
":cel",
"//cel_expr_python/ext:ext_math",
"//testing:proto2_test_all_types_py_pb2",
"@com_google_absl_py//absl/testing:absltest",
],
Expand Down
70 changes: 70 additions & 0 deletions cel_expr_python/cel_env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from absl.testing import absltest
from cel_expr_python import cel
from cel_expr_python.ext import ext_math
from cel.expr.conformance.proto2 import test_all_types_pb2 as test_all_types_pb


Expand Down Expand Up @@ -236,6 +237,75 @@ def test_config_variable_types(self):
self.assertEqual(res.type(), cel.Type.INT)
self.assertEqual(res.value(), 42)

def test_config_extensions(self):
config = cel.NewEnvConfigFromYaml("""
extensions:
- name: math
- name: strings
""")
env = cel.NewEnv(
config=config,
extensions=[TestCelExtension()],
)
yaml = env.config().to_yaml()
self.assertEqual(
normalize_yaml(yaml),
normalize_yaml("""
extensions:
- name: "math"
- name: "strings"
- name: "test_cel_extension"
"""),
)
res = env.compile("'%.4f'.format([math.sqrt(2)])").eval()
self.assertEqual(res.value(), "1.4142")
res = env.compile("hello('World')").eval()
self.assertEqual(res.value(), "Hello, World!")

def test_config_extensions_override(self):
# TODO(b/498655870): add assertion based on extension aliases once
# supported.
config = cel.NewEnvConfigFromYaml("""
extensions:
- name: cel.lib.ext.math
version: 0
- name: cel.lib.ext.strings
""")
with self.assertRaises(Exception) as e:
cel.NewEnv(
config=config,
extensions=[ext_math.ExtMath()],
)
self.assertIn(
"Extension 'cel.lib.ext.math' version 0 is already included. Cannot"
" also include version 'latest'",
str(e.exception),
)


class TestCelExtension(cel.CelExtension):
"""An example CEL extension for testing."""

def __init__(self):
super().__init__(
"test_cel_extension",
functions=[
cel.FunctionDecl(
"hello",
[
cel.Overload(
"hello(string)",
return_type=cel.Type.STRING,
parameters=[
cel.Type.STRING,
],
impl=lambda arg: f"Hello, {arg}!",
)
],
),
],
)


def normalize_yaml(yaml: str) -> str:
lines = yaml.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion cel_expr_python/ext/ext_optional.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace cel_python {

class ExtOptional : public CelExtension {
public:
explicit ExtOptional() : CelExtension("cel.lib.optional") {}
explicit ExtOptional() : CelExtension("optional") {}

absl::Status ConfigureCompiler(
cel::CompilerBuilder& compiler_builder,
Expand Down
Loading
Loading