Skip to content

Commit 76810ec

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Wrap the "lists" extension library
PiperOrigin-RevId: 966892561
1 parent 92989cf commit 76810ec

7 files changed

Lines changed: 89 additions & 2 deletions

File tree

cel_expr_python/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ py_test(
172172
data = [
173173
":cel",
174174
"//cel_expr_python/ext:ext_bindings",
175+
"//cel_expr_python/ext:ext_lists",
175176
"//cel_expr_python/ext:ext_math",
176177
"//cel_expr_python/ext:ext_optional",
177178
"//cel_expr_python/ext:ext_strings",
@@ -184,6 +185,7 @@ py_test(
184185
"//conditions:default": [
185186
":cel",
186187
"//cel_expr_python/ext:ext_bindings",
188+
"//cel_expr_python/ext:ext_lists",
187189
"//cel_expr_python/ext:ext_math",
188190
"//cel_expr_python/ext:ext_optional",
189191
"//cel_expr_python/ext:ext_strings",

cel_expr_python/ext/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ pybind_extension(
3939
],
4040
)
4141

42+
pybind_extension(
43+
name = "ext_lists",
44+
srcs = [
45+
"ext_lists.cc",
46+
],
47+
data = [
48+
"ext_lists.pyi",
49+
"//cel_expr_python:cel",
50+
],
51+
visibility = ["//visibility:public"],
52+
deps = [
53+
"//cel_expr_python:cel_extension",
54+
"@com_google_absl//absl/status",
55+
"@com_google_absl//absl/strings",
56+
"@com_google_cel_cpp//compiler",
57+
"@com_google_cel_cpp//extensions:lists_functions",
58+
"@com_google_cel_cpp//runtime:runtime_builder",
59+
"@com_google_cel_cpp//runtime:runtime_options",
60+
],
61+
)
62+
4263
pybind_extension(
4364
name = "ext_math",
4465
srcs = [

cel_expr_python/ext/ext_lists.cc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "absl/status/status.h"
16+
#include "absl/strings/str_cat.h"
17+
#include "compiler/compiler.h"
18+
#include "extensions/lists_functions.h"
19+
#include "runtime/runtime_builder.h"
20+
#include "runtime/runtime_options.h"
21+
#include "cel_expr_python/cel_extension.h"
22+
#include "cel_expr_python/py_error_status.h"
23+
24+
namespace cel_python {
25+
26+
class ExtLists : public CelExtension {
27+
public:
28+
explicit ExtLists(int version)
29+
: CelExtension("cel.lib.ext.lists", "lists", version) {
30+
if (version < 0 ||
31+
version > cel::extensions::kListsExtensionLatestVersion) {
32+
throw StatusToException(absl::InvalidArgumentError(absl::StrCat(
33+
"'lists' extension version: ", version, " not in range [0, ",
34+
cel::extensions::kListsExtensionLatestVersion, "]")));
35+
}
36+
}
37+
38+
ExtLists() : ExtLists(cel::extensions::kListsExtensionLatestVersion) {}
39+
40+
cel::CompilerLibrary GetCompilerLibrary() override {
41+
return cel::extensions::ListsCompilerLibrary(version());
42+
}
43+
44+
absl::Status ConfigureRuntime(cel::RuntimeBuilder& runtime_builder,
45+
const cel::RuntimeOptions& opts) override {
46+
return cel::extensions::RegisterListsFunctions(
47+
runtime_builder.function_registry(), opts,
48+
cel::extensions::ListsExtensionOptions{.version = version()});
49+
}
50+
};
51+
52+
CEL_VERSIONED_EXTENSION_MODULE(ext_lists, ExtLists);
53+
54+
} // namespace cel_python

cel_expr_python/ext/ext_lists.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from cel_expr_python import cel
2+
3+
class ExtLists(cel.CelExtensionBase):
4+
def __init__(self, version: int = ...) -> None: ...

conformance/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ py_test(
4040
"//cel_expr_python:cel",
4141
"//cel_expr_python/ext:ext_bindings",
4242
"//cel_expr_python/ext:ext_encoders",
43+
"//cel_expr_python/ext:ext_lists",
4344
"//cel_expr_python/ext:ext_math",
4445
"//cel_expr_python/ext:ext_optional",
4546
"//cel_expr_python/ext:ext_proto",
@@ -63,6 +64,7 @@ py_test(
6364
"//cel_expr_python:cel",
6465
"//cel_expr_python/ext:ext_bindings",
6566
"//cel_expr_python/ext:ext_encoders",
67+
"//cel_expr_python/ext:ext_lists",
6668
"//cel_expr_python/ext:ext_math",
6769
"//cel_expr_python/ext:ext_optional",
6870
"//cel_expr_python/ext:ext_proto",

conformance/conformance_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from cel_expr_python import cel
3333
from cel_expr_python.ext import ext_bindings
3434
from cel_expr_python.ext import ext_encoders
35+
from cel_expr_python.ext import ext_lists
3536
from cel_expr_python.ext import ext_math
3637
from cel_expr_python.ext import ext_optional
3738
from cel_expr_python.ext import ext_proto
@@ -73,8 +74,6 @@ class ConformanceTestSuite(unittest.TestSuite):
7374
"proto3/set_null/map_timestamp_null_pruned",
7475
"proto3/set_null/map_duration_null_pruned",
7576
"proto3/set_null/map_wrapper_null_pruned",
76-
# TODO(b/548571767): add lists_ext support
77-
"lists_ext/.*",
7877
]
7978

8079
if sys.platform == "win32":
@@ -147,6 +146,7 @@ class ConformanceTest(absltest.TestCase):
147146
EXTENSIONS_PER_TESTFILE = {
148147
"bindings_ext": [ext_bindings.ExtBindings()],
149148
"encoders_ext": [ext_encoders.ExtEncoders()],
149+
"lists_ext": [ext_lists.ExtLists()],
150150
"math_ext": [ext_math.ExtMath()],
151151
"optionals": [ext_optional.ExtOptional()],
152152
"proto2_ext": [ext_proto.ExtProto()],

release/setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ def platform_config_macos(self, cmd):
207207
'cel_expr_python.ext.ext_encoders',
208208
'//cel_expr_python/ext:ext_encoders',
209209
),
210+
BazelExtension(
211+
'cel_expr_python.ext.ext_lists',
212+
'//cel_expr_python/ext:ext_lists',
213+
),
210214
BazelExtension(
211215
'cel_expr_python.ext.ext_math',
212216
'//cel_expr_python/ext:ext_math',

0 commit comments

Comments
 (0)