Skip to content

Commit f450590

Browse files
Make google-re2 required dependency (#363)
Removes the extra and just makes google-re2 a required dependency, for simplicity. Resolves #361.
1 parent 745a41a commit f450590

File tree

6 files changed

+9
-61
lines changed

6 files changed

+9
-61
lines changed

Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ format: install $(BIN)/buf $(BIN)/license-header ## Format code
5353
.PHONY: test
5454
test: generate install gettestdata ## Run unit tests
5555
uv run -- python -m unittest
56-
$(MAKE) testextra
57-
58-
.PHONY: testextra
59-
testextra:
60-
uv sync --extra re2
61-
uv run -- python -m unittest
6256

6357
.PHONY: conformance
6458
conformance: $(BIN)/protovalidate-conformance generate install ## Run conformance tests

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ To install the package, use `pip`:
5252
pip install protovalidate
5353
```
5454

55-
Protovalidate also has an optional dependency on [google-re2](https://pypi.org/project/google-re2/). If you require re2 syntax for your regular expressions, install the extra dep as follows:
56-
57-
```shell
58-
pip install protovalidate[re2]
59-
```
60-
6155
## Documentation
6256

6357
Comprehensive documentation for Protovalidate is available at [protovalidate.com][protovalidate].

protovalidate/internal/extra_func.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@
1818
from urllib import parse as urlparse
1919

2020
import celpy
21+
import re2
2122
from celpy import celtypes
2223

2324
from protovalidate.internal import string_format
2425
from protovalidate.internal.rules import MessageType, field_to_cel
2526

26-
_USE_RE2 = True
27-
try:
28-
import re2
29-
except ImportError:
30-
_USE_RE2 = False
31-
3227
# See https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
3328
_email_regex = re.compile(
3429
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
@@ -1559,16 +1554,7 @@ def __peek(self, char: str) -> bool:
15591554
return self._index < len(self._string) and self._string[self._index] == char
15601555

15611556

1562-
def cel_matches_re(text: str, pattern: str) -> celpy.Result:
1563-
try:
1564-
m = re.search(pattern, text)
1565-
except re.error as ex:
1566-
return celpy.CELEvalError("match error", ex.__class__, ex.args)
1567-
1568-
return celtypes.BoolType(m is not None)
1569-
1570-
1571-
def cel_matches_re2(text: str, pattern: str) -> celpy.Result:
1557+
def cel_matches(text: str, pattern: str) -> celpy.Result:
15721558
try:
15731559
m = re2.search(pattern, text)
15741560
except re2.error as ex:
@@ -1577,9 +1563,6 @@ def cel_matches_re2(text: str, pattern: str) -> celpy.Result:
15771563
return celtypes.BoolType(m is not None)
15781564

15791565

1580-
cel_matches = cel_matches_re2 if _USE_RE2 else cel_matches_re
1581-
1582-
15831566
def make_extra_funcs() -> dict[str, celpy.CELFunction]:
15841567
string_fmt = string_format.StringFormat()
15851568
return {

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ dynamic = ["version"]
2424
dependencies = [
2525
"protobuf>=5",
2626
"cel-python==0.2.*",
27-
]
28-
[project.optional-dependencies]
29-
re2 = [
3027
# We need at least this version, which started publishing wheels for Python 3.13.
3128
# Ref: https://github.com/google/re2/issues/516
3229
"google-re2>=1.1.20250722; python_version == '3.13'",

test/test_matches.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import importlib.util
1615
import unittest
1716

1817
import celpy
1918
from celpy import celtypes
2019

21-
from protovalidate.internal.extra_func import cel_matches_re, cel_matches_re2
22-
23-
_USE_RE2 = True
24-
spec = importlib.util.find_spec("re2")
25-
if spec is None:
26-
_USE_RE2 = False
20+
from protovalidate.internal.extra_func import cel_matches
2721

2822

2923
class TestCollectViolations(unittest.TestCase):
30-
@unittest.skipUnless(_USE_RE2, "Requires 're2'")
3124
def test_function_matches_re2(self):
3225
empty_string = celtypes.StringType("")
3326
# \z is valid re2 syntax for end of text
34-
self.assertTrue(cel_matches_re2(empty_string, "^\\z"))
27+
self.assertTrue(cel_matches(empty_string, "^\\z"))
3528
# \Z is invalid re2 syntax
36-
self.assertIsInstance(cel_matches_re2(empty_string, "^\\Z"), celpy.CELEvalError)
37-
38-
@unittest.skipUnless(_USE_RE2 is False, "Requires 're'")
39-
def test_function_matches_re(self):
40-
empty_string = celtypes.StringType("")
41-
# \z is invalid re syntax
42-
self.assertIsInstance(cel_matches_re(empty_string, "^\\z"), celpy.CELEvalError)
43-
# \Z is valid re syntax for end of text
44-
self.assertTrue(cel_matches_re(empty_string, "^\\Z"))
29+
self.assertIsInstance(cel_matches(empty_string, "^\\Z"), celpy.CELEvalError)

uv.lock

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)