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
11 changes: 0 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ CEL specifies that regular expressions use re2 syntax,
https://github.com/google/re2/wiki/Syntax.
As of the 0.4.0 release, the Google-RE2 module is part of the CEL distribution.

.. warning:: Apple Silicon and Python 3.13

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

Google-RE2 does not build for Python 3.13 on the "darwin" platform with the "arm64" architecture.
Currently, there is no pre-built binary for Python 3.13.

The built-in ``re`` is used as a fall-back, and does work for all but a few edge cases.

Command Line
============

Expand Down
40 changes: 12 additions & 28 deletions src/celpy/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
import operator
import os
import re
from string import Template
import sys
from functools import reduce, wraps
from string import Template
from textwrap import dedent
from typing import (
Any,
Expand All @@ -80,37 +80,11 @@

import lark
import lark.visitors
import re2

import celpy.celtypes
from celpy.celparser import tree_dump

try:
import re2

def function_matches(text: str, pattern: str) -> "Result":
"""Implementation of the ``match()`` function using ``re2``"""
try:
m = re2.search(pattern, text)
except re2.error as ex:
return CELEvalError("match error", ex.__class__, ex.args)

return celpy.celtypes.BoolType(m is not None)

except ImportError: # pragma: no cover
# There is a build issue with python_version=='3.13' and sys_platform=='darwin'
# See https://github.com/google/re2/issues/516
# We fall back to using re, which passes the essential tests

def function_matches(text: str, pattern: str) -> "Result":
"""Alternative implementation of the ``match()`` function for systems where ``re2`` can't be installed."""
try:
m = re.search(pattern, text)
except re.error as ex:
return CELEvalError("match error", ex.__class__, ex.args)

return celpy.celtypes.BoolType(m is not None)


# An Annotation describes a union of types, functions, and function types.
Annotation = Union[
celpy.celtypes.TypeType,
Expand Down Expand Up @@ -420,6 +394,16 @@ def function_endsWith(
return celpy.celtypes.BoolType(string.endswith(fragment))


def function_matches(text: str, pattern: str) -> Result:
"""Implementation of the ``match()`` function using ``re2``"""
try:
m = re2.search(pattern, text)
except re2.error as ex:
return CELEvalError("match error", ex.__class__, ex.args)

return celpy.celtypes.BoolType(m is not None)


def function_getDate(
ts: celpy.celtypes.TimestampType,
tz_name: Optional[celpy.celtypes.StringType] = None,
Expand Down
Loading