Add expression interpreter#71
Conversation
4229095 to
19cdfd0
Compare
19cdfd0 to
5bda559
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #71 +/- ##
===========================================
- Coverage 90.89% 80.38% -10.52%
===========================================
Files 13 14 +1
Lines 846 994 +148
Branches 124 175 +51
===========================================
+ Hits 769 799 +30
- Misses 47 165 +118
Partials 30 30 🚀 New features to boost your workflow:
|
=== Do not change lines below ===
{
"chain": [],
"cmd": "uv lock",
"exit": 0,
"extra_inputs": [],
"inputs": [
"pyproject.toml",
"uv.lock"
],
"outputs": [
"uv.lock"
],
"pwd": "."
}
^^^ Do not change lines above ^^^
=== Do not change lines below ===
{
"chain": [],
"cmd": "uv lock",
"exit": 0,
"extra_inputs": [],
"inputs": [
"pyproject.toml",
"uv.lock"
],
"outputs": [
"uv.lock"
],
"pwd": "."
}
^^^ Do not change lines above ^^^
|
From today's call, here's a quick-and-dirty proxy to allow you to provide multiple namespaces and treat them as one: class LookupProxy:
def __init__(self, *objs):
self.objs = objs
def __getitem__(self, key):
for obj in self.objs:
if isinstance(obj, dict) and key in obj:
return obj[key]
if hasattr(obj, key):
return getattr(obj, key)
raise AttributeError
# Provide either attr or item lookup
__getattr__ = __getitem__Example usage: import bids_validator as bv
import bids_validator.context
from bids_validator import expression_language as el
from bids_validator.types.files import FileTree
from bidsschematools.schema import load_schema
schema = load_schema()
root = FileTree.read_from_filesystem('tests/data/bids-examples/ds000117/')
ds = bv.context.Dataset(root, schema)
file = root / 'sub-01' / 'ses-mri' / 'anat' / 'sub-01_ses-mri_acq-mprage_T1w.nii.gz'
context = bv.context.Context(file, ds, None)
namespace = LookupProxy(el.ids, context) |
Primary change is in Element case to handle nulls, changes in Function case are more for my understanding
|
The |
|
Needs further work:
For future work:
|
|
Okay, I have created a function for |
|
I think as a method on the context is probably simplest. The alternative would be as a function that takes a context as an argument, and then the proxy setup uses |
|
Yep that works, and the evaluator can find and use it from the namespace produced by the |
effigies
left a comment
There was a problem hiding this comment.
Looking good. A few notes.
To match the TS version
Here's the initial attempt at adding all the parts of the expression language interpreter.
These successfully cover the full range of tests in the
bidsschematoolsexpression tests.Two things that still need addressing:
existspasses the tests but needs more work to actually work as described in the schema tools docsContext