| @@ -502,6 +502,31 @@ |
| 502 | 502 | nanosecond precision; matching would discard sub-second precision). Named-argument |
| 503 | 503 | call variants stay out of the slice (the AST is positional-only, ADR-15). |
| 504 | 504 | |
| 505 | +## ADR-20: Python bindings (`feel-py`, PyO3 + maturin) |
| 506 | + |
| 507 | +- **Context:** feel-core already has a Postgres wrapper (feel-pg) and a WASM wrapper |
| 508 | + (feel-wasm); Python is a common host for decision logic and data pipelines. A |
| 509 | + fourth wrapper should expose FEEL to Python without touching the pure core (ADR-1): |
| 510 | + all target glue, including the JSON/native boundary mapping, lives in the wrapper. |
| 511 | +- **Decision (2026-06-16):** new `crates/feel-py`, built with **PyO3 0.28 + maturin** |
| 512 | + (`abi3-py39` → a single wheel for every CPython ≥ 3.9). Surface mirrors feel-wasm: |
| 513 | + free `evaluate(expr, context=None)` / `evaluate_strict(...)` plus a `compile(expr)` |
| 514 | + returning a reusable `CompiledExpr` (parse-once / evaluate-many). The lenient/strict |
| 515 | + null policy is ADR-14; a parse/eval error or a strict error-null raises |
| 516 | + `feel.FeelError` (a subclass of `ValueError`). `now()`/`today()` read the system |
| 517 | + clock as a fixed-offset UTC instant. The three boundary sub-decisions are recorded |
| 518 | + as **RD-4** (regex dialect), **RD-5** (temporal mapping) and **RD-6** (context |
| 519 | + mapping). `feel-py` keeps feel-core's default features (so `RustRegex` is available |
| 520 | + as the `xpath-regex` provider, and the system tzdb resolves named zones) and is in |
| 521 | + the workspace `members` but **not** `default-members` — it needs a PyO3 link context |
| 522 | + (built via maturin), like feel-pg needs pgrx. |
| 523 | +- **Consequence:** a fourth target on the same core, verified by 21 pytest cases |
| 524 | + (`crates/feel-py/tests`) plus a Rust unit test for the replacement-string |
| 525 | + translation. Alongside it, **feel-wasm's `js_to_value` was hardened** with the same |
| 526 | + cycle/depth guard feel-py uses: its recursion was previously unbounded, so a cyclic |
| 527 | + JS object (`a.b = a`, legal in JS) could overflow the stack; a back-edge now maps to |
| 528 | + `null` (no other behaviour change — own-enumerable getters still fire as before). |
| 529 | + |
| 505 | 530 | ## Revisable design decisions |
| 506 | 531 | |
| 507 | 532 | Softer than the ADRs above: deliberate, **reversible** choices that are not |
| @@ -581,6 +606,74 @@ |
| 581 | 606 | - **If flipped:** add `iana-tz` to a `default` feature on feel-wasm (or document |
| 582 | 607 | building with it), accepting the larger default bundle. |
| 583 | 608 | |
| 609 | +### RD-4: feel-py uses the Python `re` regex dialect (`xpath-regex` to opt out) |
| 610 | + |
| 611 | +- **Weighed:** ADR-16 makes the three regex builtins host-pluggable. Unlike feel-pg |
| 612 | + (RD-1, which kept `RustRegex` for TCK-dialect parity) and like feel-wasm (JS |
| 613 | + dialect), Python ships its own `re` engine, and the FEEL/XPath flags `i s m x q` |
| 614 | + all carry over — `i/s/m/x` as inline `(?…)` flags, `q` via `re.escape`, and inline |
| 615 | + flags in the pattern pass straight through. So the host dialect is both available |
| 616 | + and idiomatic for Python authors. Against: `re` is a third dialect that diverges |
| 617 | + from feel-core/TCK in the corners (Python supports backreferences the Rust engine |
| 618 | + rejects; class subtraction/XSD block names differ). |
| 619 | +- **Decision (2026-06-16):** feel-py defaults to the Python `re` dialect via a |
| 620 | + `PyRegex` provider (it holds the GIL, since the builtins call back into Python). The |
| 621 | + `xpath-regex` build feature instead compiles feel-core's `RustRegex`, for results |
| 622 | + byte-identical to feel-core/TCK. XPath `$N` replacement references are translated to |
| 623 | + `re`'s `\g<N>` form (`xpath_replacement_to_python`, the Python pendant of feel-core's |
| 624 | + `xpath_replacement_to_rust`). Edge: a capturing group in a `split` delimiter makes |
| 625 | + `re.split` emit the captures (XPath does not) → such a result is a FEEL null |
| 626 | + (documented divergence). |
| 627 | +- **Revisit trigger:** users expect FEEL regex in Python to match feel-core/TCK by |
| 628 | + default (e.g. patterns authored against the reference) rather than the `re` dialect. |
| 629 | +- **If flipped:** make `xpath-regex` the default feature (or document building with |
| 630 | + it); the seam (`evaluate_with_env` + the `cfg` provider switch) is already in place. |
| 631 | + |
| 632 | +### RD-5: feel-py temporal mapping (native types; years-months via relativedelta) |
| 633 | + |
| 634 | +- **Weighed:** ADR-18's boundary is canonical ISO-8601. Python has native |
| 635 | + `datetime.date`/`datetime`/`time`/`timedelta`, but **no** native years-months |
| 636 | + duration. Options for that one type: an ISO string (as feel-wasm leaves durations), |
| 637 | + `dateutil.relativedelta` (a real, arithmetic-capable type), or a bespoke class. |
| 638 | +- **Decision (2026-06-16):** map `date`→`date`, `date and time`→`datetime`, |
| 639 | + `time`→`time`, days-time-duration→`timedelta`, and years-months-duration→ |
| 640 | + `dateutil.relativedelta` — adding `python-dateutil` as a runtime dependency. Input |
| 641 | + is symmetric (a native temporal in the context maps back to the FEEL type; a |
| 642 | + `relativedelta`'s years/months become a years-months duration, its other fields |
| 643 | + ignored — FEEL has no mixed duration). The conversion goes through the ISO bridge |
| 644 | + (`to_iso`/`temporal_from_iso`) except the two durations, which are built from |
| 645 | + components. |
| 646 | +- **Revisit trigger:** a desire for zero runtime dependencies (drop `python-dateutil`). |
| 647 | +- **If flipped:** return years-months durations as an ISO-8601 string or a small |
| 648 | + module-level class; drop the `python-dateutil` dependency. |
| 649 | + |
| 650 | +### RD-6: feel-py context mapping is eager, not lazy (no `Value::Foreign` in the core) |
| 651 | + |
| 652 | +- **Weighed:** FEEL has only the dot for member access (`Expr::Path`), resolved |
| 653 | + **inside feel-core** against a fully materialised `Value` tree — there is no live |
| 654 | + Python object at evaluation time. A *lazy* alternative (feel-core calling `getattr` |
| 655 | + back into Python per path segment) was considered and **rejected**: it would need an |
| 656 | + opaque `Value::Foreign` variant in the core, which duck-types the evaluator (every |
| 657 | + type-inspecting op — `distinct`, arithmetic, comparison — would have to "force" the |
| 658 | + value via the host) and lands the concept in *all* targets (pg/wasm) though only |
| 659 | + Python would create such values — against the spirit of ADR-1. Lazy `getattr` would |
| 660 | + also fire `@property`/descriptors, i.e. side effects / lazy DB loads on ORM rows. |
| 661 | +- **Decision (2026-06-16):** convert **eagerly** at the boundary. A `dict` maps by its |
| 662 | + keys; any other object maps from its instance `__dict__` (`vars(obj)`) — instance |
| 663 | + data only, so descriptors/properties/methods are **never** invoked (no side effects), |
| 664 | + mirroring feel-wasm's `Object.keys` model. Keys beginning with `_` (dunders and |
| 665 | + internal bookkeeping like `_sa_instance_state`) are skipped. A `__dict__`-less object |
| 666 | + (`__slots__`) is not introspectable → null. An `id()`-based cycle guard plus a depth |
| 667 | + cap break reference cycles (a back-edge → null), since loaded bidirectional ORM |
| 668 | + graphs / parent-child trees can be cyclic; on acyclic dict data neither triggers. |
| 669 | +- **Revisit trigger:** a real need to evaluate against very large or genuinely live |
| 670 | + object graphs where an eager snapshot is too costly — *and* a way to do it without a |
| 671 | + foreign value in the core. |
| 672 | +- **If flipped:** add a `HostPath` resolver trait to `EvalEnv` plus a |
| 673 | + `Value::Foreign(handle)` variant in feel-core (an ADR-16-style seam), with |
| 674 | + force-on-consume rules for non-path operations — a feel-core change warranting its |
| 675 | + own ADR. |
| 676 | + |
| 584 | 677 | ## Roadmap: deferred scope (recorded, not yet built) |
| 585 | 678 | |
| 586 | 679 | These were considered and deliberately deferred to keep the slice thin. Listed so |