Skip to content

Commit 0e53c7d

Browse files
authored
- Switch to uv - Switch to lark 1.2 - Adjust pyproject.toml to handle re2-stubs as a developer option.
1 parent 3e75bcf commit 0e53c7d

12 files changed

Lines changed: 929 additions & 1541 deletions

File tree

‎Dockerfile‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Dockerfile to create an Ubuntu image with curl, git, vim, and uv
2+
# docker build -t dev-ubuntu .
3+
# docker image prune
4+
# docker run --name working -it dev-ubuntu
5+
# From the interactive prompt, cd /home/cel-python, run commands normally.
6+
# docker container rm working
7+
8+
FROM ubuntu:latest
9+
10+
# Update package manager and install curl command
11+
RUN apt update && apt install -y aptitude
12+
RUN aptitude install -y curl
13+
RUN aptitude install -y git
14+
RUN aptitude install -y vim
15+
16+
# Install uv using the curl command
17+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
18+
19+
# Use GIT to get the package
20+
RUN cd /home && git clone https://github.com/cloud-custodian/cel-python.git
21+
22+
# Run the bash terminal on container startup
23+
CMD /bin/bash
24+

‎README.rst‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Installation
3333

3434
::
3535

36-
pip install cel-python
36+
python -m pip install cel-python
3737

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

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

5050
::
5151

52-
pip install cel-python[re2]
52+
python -m pip install cel-python[re2]
5353

54+
.. warning:: Apple Silicon
55+
56+
See https://github.com/google/re2/issues/453,
57+
https://github.com/google/re2/issues/346,
58+
https://github.com/google/re2/issues/516
59+
60+
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.
5461

5562
Command Line
5663
============

‎features/steps/cli_binding.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
CLI Bindings for Behave testing.
1818
1919
These step definitions use ``subprocess.run()`` to run the ``celpy`` app as a separate process.
20+
21+
The command-line parameters these step-bindings use.
22+
23+
* ``-D PYTHONPATH=p`` sets the ``PYTHONPATH`` environment variable for this run.
24+
* ``-D env=name`` sets the virtual environment name, creates a .test/name directory for temporary files
25+
* ``-D debug=True`` produces additional debugging output
2026
"""
2127
import re
2228
import shlex

‎poetry.lock‎

Lines changed: 0 additions & 1419 deletions
This file was deleted.

‎pyproject.toml‎

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,66 @@
1313
# limitations under the License.
1414
#
1515

16-
[tool.poetry]
16+
[project]
1717
name = "cel-python"
18-
version = "0.3.0"
18+
version = "0.4.0"
1919
description = "Pure Python implementation of Google Common Expression Language"
20-
authors = ["S. Lott <slott56@gmail.com>"]
2120
readme = "README.rst"
22-
license = "LICENSE.txt"
21+
license-files = ["LICENSE"]
2322
classifiers = [
2423
"Development Status :: 4 - Beta",
2524
"Programming Language :: Python"
2625
]
26+
authors = [
27+
{ name = "S.Lott", email = "slott56@gmail.com" }
28+
]
29+
requires-python = ">=3.9"
2730
packages = [{ include = "celpy", from = "src"}]
2831

29-
[tool.poetry.dependencies]
30-
python = "^3.9"
31-
lark = "^0.12"
32+
dependencies = [
33+
"lark>=1.2.2",
34+
"pendulum>=3.1.0",
35+
"pyyaml>=6.0.2",
36+
"jmespath>=1.0.1",
37+
]
3238

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

36-
# specify as a non default group for building automatically in ci without -e
37-
pendulum = "^3.1.0"
38-
pyyaml = "^6.0.2"
39-
types-pyyaml = "^6.0.12.20250516"
40-
[tool.poetry.group.c7n.dependencies]
41-
jmespath = "^1.0.1"
42-
google-re2 = { version = "^1.0", optional = true }
42+
[project.optional-dependencies]
43+
re2 = [
44+
"google-re2",
45+
]
4346

44-
[tool.poetry.extras]
45-
re2 = ["google-re2"]
47+
[build-system]
48+
requires = ["hatchling"]
49+
build-backend = "hatchling.build"
4650

47-
[tool.poetry.group.dev.dependencies]
48-
behave = "^1.2.6"
49-
ruff = "^0.9.6"
50-
mypy = "^1.10.0"
51-
pytest = "^8.2.1"
52-
pytest-cov = "^5.0.0"
53-
sphinx = "^6.0"
54-
tox = "^4.15.0"
55-
pre-commit = "^3.5"
56-
google-re2-stubs = "^0.1.0"
51+
#[build-system]
52+
#requires = ["uv_build>=0.7.7,<0.8.0"]
53+
#build-backend = "uv_build"
5754

58-
[build-system]
59-
requires = ["poetry-core"]
60-
build-backend = "poetry.core.masonry.api"
55+
#[build-system]
56+
#requires = ["flit"]
57+
#build-backend = "flit.api:main"
58+
59+
#[build-system]
60+
#requires = ["pdm-backend"]
61+
#build-backend = "pdm.backend"
62+
63+
#[build-system]
64+
#requires = ["setuptools", "setuptools-scm"]
65+
#build-backend = "setuptools.build_meta"
6166

62-
[tool.pytest.ini_options]
63-
markers = [
64-
"refactor: tests that need to be refactored to use celfilter_instance"
67+
[dependency-groups]
68+
dev = [
69+
"behave>=1.2.6",
70+
"coverage>=7.8.1",
71+
"mypy>=1.15.0",
72+
"pytest>=8.3.5",
73+
"ruff>=0.11.10",
74+
"tox>=4.24",
75+
"tox-uv>=1.25.0",
76+
"types-pyyaml>=6.0.12.20250516",
77+
"google-re2-stubs",
6578
]

‎src/cel_python/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main() -> None:
2+
print("Hello from cel-python!")

‎src/celpy/celparser.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def __init__(self) -> None:
9595
g_regex_flags=re.M,
9696
lexer_callbacks={"IDENT": self.ambiguous_literals},
9797
propagate_positions=True,
98+
maybe_placeholders=False,
99+
priority="invert",
98100
)
99101

100102
@staticmethod

‎src/celpy/evaluation.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
import celpy.celtypes
6868
from celpy.celparser import tree_dump
6969

70-
_USE_RE2 = True
70+
_USE_RE2 = False
7171
try:
7272
import re2
73+
_USE_RE2 = True
7374
except ImportError: # pragma: no cover
74-
_USE_RE2 = False
75+
pass
7576

7677
# A CEL type annotation. Used in an environment to describe objects as well as functions.
7778
# This is a list of types, plus Callable for conversion functions.
@@ -1968,12 +1969,12 @@ def member_dot(self, tree: lark.Tree) -> Result:
19681969
property_name = property_name_token.value
19691970
result: Result
19701971
if isinstance(member, CELEvalError):
1971-
result = member
1972+
result = cast(Result, member)
19721973
elif isinstance(member, NameContainer):
19731974
# Navigation through names provided as external run-time bindings.
19741975
# The dict is the value of a Referent that was part of a namespace path.
19751976
if property_name in member:
1976-
result = member[property_name].value
1977+
result = cast(Result, member[property_name].value)
19771978
else:
19781979
err = f"No {property_name!r} in bindings {sorted(member.keys())}"
19791980
result = CELEvalError(err, KeyError, None, tree=tree)
@@ -2409,8 +2410,8 @@ def literal(self, tree: lark.Tree) -> Result:
24092410
else:
24102411
raise CELUnsupportedError(
24112412
f"{tree.data} {tree.children}: type not implemented",
2412-
line=value_token.line,
2413-
column=value_token.column,
2413+
line=value_token.line or tree.meta.line,
2414+
column=value_token.column or tree.meta.column,
24142415
)
24152416
except ValueError as ex:
24162417
result = CELEvalError(ex.args[0], ex.__class__, ex.args, tree=tree)

0 commit comments

Comments
 (0)