Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docs/source/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ We'll look at integration of CEL into another application from four perspectives

5. Finally, `External API`_ will review some elements of the API that are part of the integration interface.

The CEL compile and evaluation is designed to work inside a single thread.
In an application where multiple, concurrent threads will be performing CEL evaluations, each thread requires a distinct copy of a stateful :py:class:`celpy.Environment` instance.

Integration Essentials
======================

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies = [
"pendulum>=3.2.0",
"pyyaml>=6.0.3",
"tomli >= 1.1.0 ; python_version < '3.11'",
"ipykernel>=7.2.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one seems odd, and brings in a large dependency stack

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You! Should be in dev -- it's for a notebook to analyze the conformance test cases.

]

[project.urls]
Expand Down Expand Up @@ -88,7 +89,7 @@ dev = [
]

[tool.tox]
envlist = ["py310", "py311", "py312", "py313", "lint", "tools"]
envlist = ["py310", "py311", "py312", "py313", "py314", "lint", "tools"]
minversion = "4.24.0"

[tool.tox.env_run_base]
Expand Down
4 changes: 4 additions & 0 deletions src/celpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ class Environment:
At this time, external functions are bound to the CEL expression.
The :py:class:`celpy.Runnable` can be evaluated repeatedly with multiple inputs, avoiding the overheads of compiling for each input value.
.. note:: This cannot be shared by multiple threads.
Each thread must have an ``Environment`` instance.
.. todo:: For a better fit with Go language expectations
- A type adapters registry makes other native types available for CEL.
Expand Down
25 changes: 14 additions & 11 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
C7N Type Adapter Test Cases.
"""

import datetime

import celpy.adapter
Expand All @@ -28,30 +29,32 @@ def test_json_to_cel():
assert str(celpy.adapter.json_to_cel(False)) == str(celpy.celtypes.BoolType(False))
assert celpy.adapter.json_to_cel(2.5) == celpy.celtypes.DoubleType(2.5)
assert celpy.adapter.json_to_cel(42) == celpy.celtypes.IntType(42)
assert celpy.adapter.json_to_cel("Hello, world!") == celpy.celtypes.StringType("Hello, world!")
assert celpy.adapter.json_to_cel("Hello, world!") == celpy.celtypes.StringType(
"Hello, world!"
)
assert celpy.adapter.json_to_cel(None) is None
assert celpy.adapter.json_to_cel(["Hello", "world!"]) == celpy.celtypes.ListType(
[
celpy.celtypes.StringType("Hello"),
celpy.celtypes.StringType("world!"),
]
)
assert celpy.adapter.json_to_cel(tuple(["Hello", "world!"])) == celpy.celtypes.ListType(
assert celpy.adapter.json_to_cel(
tuple(["Hello", "world!"])
) == celpy.celtypes.ListType(
[
celpy.celtypes.StringType("Hello"),
celpy.celtypes.StringType("world!"),
]
)
assert celpy.adapter.json_to_cel({"Hello": "world!"}) == celpy.celtypes.MapType(
{
celpy.celtypes.StringType("Hello"):
celpy.celtypes.StringType("world!"),
celpy.celtypes.StringType("Hello"): celpy.celtypes.StringType("world!"),
}
)
assert (
celpy.adapter.json_to_cel(datetime.datetime(2020, 9, 10, 11, 12, 13, tzinfo=datetime.timezone.utc))
== celpy.celtypes.TimestampType("2020-09-10T11:12:13Z")
)
assert (
celpy.adapter.json_to_cel(datetime.timedelta(days=42)) == celpy.celtypes.DurationType("42d")
)
assert celpy.adapter.json_to_cel(
datetime.datetime(2020, 9, 10, 11, 12, 13, tzinfo=datetime.timezone.utc)
) == celpy.celtypes.TimestampType("2020-09-10T11:12:13Z")
assert celpy.adapter.json_to_cel(
datetime.timedelta(days=42)
) == celpy.celtypes.DurationType("42d")
Loading
Loading