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
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Dockerfile to create an Ubuntu image with curl, git, vim, and uv
# docker build -t dev-ubuntu .
# docker image prune
# docker run --name working -it dev-ubuntu
# From the interactive prompt, cd /home/cel-python, run commands normally.
# docker container rm working

FROM ubuntu:latest

# Update package manager and install curl command
RUN apt update && apt install -y aptitude
RUN aptitude install -y curl
RUN aptitude install -y git
RUN aptitude install -y vim

# Install uv using the curl command
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

# Use GIT to get the package
RUN cd /home && git clone https://github.com/cloud-custodian/cel-python.git

# Run the bash terminal on container startup
CMD /bin/bash

11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Installation

::

pip install cel-python
python -m pip install cel-python

You now have the CEL run-time available to Python-based applications.

Expand All @@ -49,8 +49,15 @@ library ``re`` syntax by default. If a ``re2`` package is installed or the

::

pip install cel-python[re2]
python -m pip install cel-python[re2]

.. warning:: Apple Silicon

See https://github.com/google/re2/issues/453,
https://github.com/google/re2/issues/346,
https://github.com/google/re2/issues/516

As of the 0.4.0 release, the google-re2 package does not build for Python 3.13 on the "darwin" platform with the "arm64" architecture.

Command Line
============
Expand Down
6 changes: 6 additions & 0 deletions features/steps/cli_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
CLI Bindings for Behave testing.

These step definitions use ``subprocess.run()`` to run the ``celpy`` app as a separate process.

The command-line parameters these step-bindings use.

* ``-D PYTHONPATH=p`` sets the ``PYTHONPATH`` environment variable for this run.
* ``-D env=name`` sets the virtual environment name, creates a .test/name directory for temporary files
* ``-D debug=True`` produces additional debugging output
"""
import re
import shlex
Expand Down
1,419 changes: 0 additions & 1,419 deletions poetry.lock

This file was deleted.

81 changes: 47 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,66 @@
# limitations under the License.
#

[tool.poetry]
[project]
name = "cel-python"
version = "0.3.0"
version = "0.4.0"
description = "Pure Python implementation of Google Common Expression Language"
authors = ["S. Lott <slott56@gmail.com>"]
readme = "README.rst"
license = "LICENSE.txt"
license-files = ["LICENSE"]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python"
]
authors = [
{ name = "S.Lott", email = "slott56@gmail.com" }
]
requires-python = ">=3.9"
packages = [{ include = "celpy", from = "src"}]

[tool.poetry.dependencies]
python = "^3.9"
lark = "^0.12"
dependencies = [
"lark>=1.2.2",
"pendulum>=3.1.0",
"pyyaml>=6.0.2",
"jmespath>=1.0.1",
]

# specify as optional for pip install cel-python[c7n] or poetry install -e behavior
jmespath = { version = "^1.0.1", optional = true }
[project.scripts]
cel-python = "cel_python:main"

# specify as a non default group for building automatically in ci without -e
pendulum = "^3.1.0"
pyyaml = "^6.0.2"
types-pyyaml = "^6.0.12.20250516"
[tool.poetry.group.c7n.dependencies]
jmespath = "^1.0.1"
google-re2 = { version = "^1.0", optional = true }
[project.optional-dependencies]
re2 = [
"google-re2",
]

[tool.poetry.extras]
re2 = ["google-re2"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.group.dev.dependencies]
behave = "^1.2.6"
ruff = "^0.9.6"
mypy = "^1.10.0"
pytest = "^8.2.1"
pytest-cov = "^5.0.0"
sphinx = "^6.0"
tox = "^4.15.0"
pre-commit = "^3.5"
google-re2-stubs = "^0.1.0"
#[build-system]
#requires = ["uv_build>=0.7.7,<0.8.0"]
#build-backend = "uv_build"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
#[build-system]
#requires = ["flit"]
#build-backend = "flit.api:main"

#[build-system]
#requires = ["pdm-backend"]
#build-backend = "pdm.backend"

#[build-system]
#requires = ["setuptools", "setuptools-scm"]
#build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
markers = [
"refactor: tests that need to be refactored to use celfilter_instance"
[dependency-groups]
dev = [
"behave>=1.2.6",
"coverage>=7.8.1",
"mypy>=1.15.0",
"pytest>=8.3.5",
"ruff>=0.11.10",
"tox>=4.24",
"tox-uv>=1.25.0",
"types-pyyaml>=6.0.12.20250516",
"google-re2-stubs",
]
2 changes: 2 additions & 0 deletions src/cel_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main() -> None:
print("Hello from cel-python!")
2 changes: 2 additions & 0 deletions src/celpy/celparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def __init__(self) -> None:
g_regex_flags=re.M,
lexer_callbacks={"IDENT": self.ambiguous_literals},
propagate_positions=True,
maybe_placeholders=False,
priority="invert",
)

@staticmethod
Expand Down
13 changes: 7 additions & 6 deletions src/celpy/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@
import celpy.celtypes
from celpy.celparser import tree_dump

_USE_RE2 = True
_USE_RE2 = False
try:
import re2
_USE_RE2 = True
except ImportError: # pragma: no cover
_USE_RE2 = False
pass

# A CEL type annotation. Used in an environment to describe objects as well as functions.
# This is a list of types, plus Callable for conversion functions.
Expand Down Expand Up @@ -1968,12 +1969,12 @@ def member_dot(self, tree: lark.Tree) -> Result:
property_name = property_name_token.value
result: Result
if isinstance(member, CELEvalError):
result = member
result = cast(Result, member)
elif isinstance(member, NameContainer):
# Navigation through names provided as external run-time bindings.
# The dict is the value of a Referent that was part of a namespace path.
if property_name in member:
result = member[property_name].value
result = cast(Result, member[property_name].value)
else:
err = f"No {property_name!r} in bindings {sorted(member.keys())}"
result = CELEvalError(err, KeyError, None, tree=tree)
Expand Down Expand Up @@ -2409,8 +2410,8 @@ def literal(self, tree: lark.Tree) -> Result:
else:
raise CELUnsupportedError(
f"{tree.data} {tree.children}: type not implemented",
line=value_token.line,
column=value_token.column,
line=value_token.line or tree.meta.line,
column=value_token.column or tree.meta.column,
)
except ValueError as ex:
result = CELEvalError(ex.args[0], ex.__class__, ex.args, tree=tree)
Expand Down
Loading
Loading