Closed gilesknap closed 4 weeks ago
I'm still slightly nervous of not being able to include escaping, seems like it might cause difficult to change issues down the line.
Also, how would a pathological case like this render?
- type: motorSim.simMotorAxis
DESC: "{{ ADDR }}"
ADDR: "{{ DESC }}"
I've got a potential idea, instead of populating the context with the values, populate them with deferred renderers, e.g.
@dataclass
Class DeferredRender:
value: str
context: Dict[str, Any]
@lru_cache # maybe?
def __str__(self) -> str:
return render(self.value, self.context)
context = {}
for arg _name, arg_value in args.items():
context[arg_name] = DeferredRender(arg_value, context)
Then let Python's recursion size limit catch the recursive case
DeferredRender
seems really neat.
that is pretty cool 🤓
Note that we don't want to do this for objects because we want to use dot-member
.
The rendering as of 3.0.0b6 is all done during the model validator for the IOC instance. All typed fields are also allowed to be str as long as the str contains {{.*}}
.
https://github.com/epics-containers/ibek/blob/list-arg2dict-param/src/ibek/ioc.py#L97-L122
Ibek Schema Proposal
The problem
At present the Support Yaml Args must be set to type
str
if they are ever allowed to have Jinja templating.This is counter productive because:
The solution
@GDYendell and @gilesknap propose that we make all arguments templatable as follows:
all other types will have a new scheme, below I use the example of
int
but this applies tofloat
,bool
, etc.int
in the Support YAML as beforeint | str
\"{{ .* ?\| ?int ?}}\"
"{{ myvalue * yourvalue + 1 | int}}"
ec ioc validate
command will evaluate the Args and this means that you will get checks that the expression evaluates to something that can be cast toint
.Additionally
As part of this change we also propose that the Jinja rendering be run repeatedly as follows
This means that we can have nested references to rendered values. For example:
Without a second pass of this we would have
DESC
=CS Motor {{ 1 + axis_start | int }}
The downside of this approach is that there is no possibility of using escaping to put
{{
and}}
in the final result.@coretl I would like to get your sign off on this
Additionally
feature - what do you think?