Skip to content

Commit 23dcce2

Browse files
committed
drift
1 parent 7e6444e commit 23dcce2

3 files changed

Lines changed: 14 additions & 23 deletions

File tree

protovalidate/internal/_core.py

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

15-
"""Backend-agnostic rule-engine primitives shared by both CEL backends.
16-
17-
``Violation``, ``RuleContext``, ``CompilationError``, and the ``Rules`` ABC do
18-
not depend on the CEL implementation (celpy vs cel-expr-python) or the
19-
descriptor/value model (protobuf-py vs google.protobuf) — they only speak the
20-
public ``validate_pb`` path types. Both the celpy engine (``rules.py``) and the
21-
cel-expr-python engine (``celexpr/rules.py``) import them from here so violation
22-
output and path bookkeeping are identical across backends.
23-
"""
15+
"""Backend-agnostic rule-engine primitives shared by both CEL backends."""
2416

2517
import abc
2618
import typing
@@ -33,12 +25,7 @@ class CompilationError(Exception):
3325

3426

3527
class Violation:
36-
"""A singular rule violation.
37-
38-
Field and rule paths accumulate as element lists during recursion
39-
(messages are immutable and do not auto-vivify), then materialize into a
40-
``validate_pb.Violation`` lazily via :attr:`proto`.
41-
"""
28+
"""A singular rule violation."""
4229

4330
field_value: typing.Any
4431
rule_value: typing.Any
@@ -69,7 +56,6 @@ def extend_rule_elements(self, elements: list[validate_pb.FieldPathElement]) ->
6956
self._rule_elements.extend(elements)
7057

7158
def finalize_paths(self) -> None:
72-
"""Reverses the accumulated leaf-to-root paths into root-to-leaf order."""
7359
self._field_elements.reverse()
7460
self._rule_elements.reverse()
7561

protovalidate/internal/backend.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
``CEL_EXPR_AVAILABLE`` to ``False`` before constructing a ``Validator``.
2323
"""
2424

25-
import importlib.util
26-
27-
2825
def _detect() -> bool:
29-
return all(importlib.util.find_spec(name) is not None for name in ("cel_expr_python", "google.protobuf"))
26+
# Actually import (rather than importlib.util.find_spec) so an installed but
27+
# broken wheel — cel-expr-python ships only native wheels with spotty
28+
# coverage, so a failed extension load is a real possibility — falls back to
29+
# celpy instead of being reported available and then crashing at use.
30+
try:
31+
import cel_expr_python # noqa: F401, PLC0415
32+
import google.protobuf.message # noqa: F401, PLC0415
33+
except ImportError:
34+
return False
35+
return True
3036

3137

3238
CEL_EXPR_AVAILABLE: bool = _detect()

protovalidate/internal/celexpr/rules.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
in google's global pool for discovery. Rules are *evaluated* by cel-expr-python,
2222
which only ingests google messages, so the message under validation and the rule
2323
messages bound as ``rules``/``rule`` are bridged to google (see
24-
``celexpr.bridge.GoogleBridge``). Output ``Violation``\\s are protobuf-py
25-
``validate_pb`` messages — the public type, shared with the celpy engine via
26-
``protovalidate.internal._core``.
24+
``_bridge.GoogleBridge``). Output ``Violation``\\s are protobuf-py ``validate_pb``
25+
messages — the public type.
2726
"""
2827

2928
import dataclasses

0 commit comments

Comments
 (0)