Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre_values and Jinja strict mode #223

Merged
merged 7 commits into from
May 30, 2024
Merged

Add pre_values and Jinja strict mode #223

merged 7 commits into from
May 30, 2024

Conversation

gilesknap
Copy link
Member

This PR includes the final changes to make the technosoft motor example work well.

First we have added a new pre_values key to Definition. When fields of an Entity are being evaluated they are done in this order:

  • pre_values
  • args
  • values

This allows us to generate values that can be used throughout the args and also values that can rely on all the args being already rendered. This is important when we are using Jinja rendering in these fields.

The example of the num value in

pre_values:
- name: num
description: The auto incrementing axis number
value: |-
{{ __utils__.counter("motorTML.axisCount", start=0) }}

required pre_values because it is needed both in the CONFIG arg and also in the pre_init

This PR also introduces strict Jinja rendering that will fail if you use non-existent variables. With additional test to validate the feature.

@gilesknap
Copy link
Member Author

@coretl @GDYendell it's naming time!

I said to Tom I did not want to change the name of 'values' but I've checked and this as yet undocumented feature is currently only used in the technosoft support yaml.

Therefore we have an opportunity to change the names:

  • pre_values
  • values
    To something more consistent.

Any ideas?

@gilesknap
Copy link
Member Author

ALSO: I have this feeling that it would be real nice if ALL 'pre_values' were evaluated before ANY args.

With that feature I could then have the controller know how many axes got greated and not have to manually declare the axis count in the controller YAML.

@amichelotti
Copy link

This PR includes the final changes to make the technosoft motor example work well.

First we have added a new pre_values key to Definition. When fields of an Entity are being evaluated they are done in this order:

  • pre_values
  • args
  • values

This allows us to generate values that can be used throughout the args and also values that can rely on all the args being already rendered. This is important when we are using Jinja rendering in these fields.

The example of the num value in

pre_values:
- name: num
description: The auto incrementing axis number
value: |-
{{ __utils__.counter("motorTML.axisCount", start=0) }}

required pre_values because it is needed both in the CONFIG arg and also in the pre_init
This PR also introduces strict Jinja rendering that will fail if you use non-existent variables. With additional test to validate the feature.

Good job, it seems to me a clean way.

@gilesknap
Copy link
Member Author

@amichelotti I have released this to PyPI as 3.0.0b4 so you can try in your generic IOC if you like.

@gilesknap
Copy link
Member Author

@coretl @GDYendell it's naming time!

I said to Tom I did not want to change the name of 'values' but I've checked and this as yet undocumented feature is currently only used in the technosoft support yaml.

Therefore we have an opportunity to change the names:

  • pre_values
  • values
    To something more consistent.

Any ideas?

And it has occured to me that Args are not really arguments they are parameters. But I really don't want to change that.

@coretl
Copy link
Contributor

coretl commented May 17, 2024

How about pre_defines (done before making any Entities) and post_defines (done after making Entities but before rendering them)?

@gilesknap
Copy link
Member Author

How about pre_defines (done before making any Entities) and post_defines (done after making Entities but before rendering them)?
Not bad!

@GDYendell
Copy link
Member

GDYendell commented May 17, 2024

And it has occured to me that Args are not really arguments they are parameters. But I really don't want to change that.

This is true. I believe the convention is parameters are the definitions and arguments are the actual values. But, given we don't use the term parameters (yet?) I don't think this is particularly confusing.

gilesknap added 5 commits May 17, 2024 17:05
Makes for faster test and decouples from arbitrary other
repo
add _ctx_ as a short alias for __utils__
add get and set functions as aliases of get_var set_var
make get have a default for non pre-existing variables
make set return the value it is setting for jinja render purposes
make all variables created with get/set directly available in the context
@gilesknap gilesknap merged commit 65210c6 into main May 30, 2024
25 of 26 checks passed
@gilesknap gilesknap deleted the motor-demo2 branch June 18, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants