From 9cf2cea41ef72e005c957b03e80c87f0bf258a54 Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Mon, 30 Oct 2023 09:25:00 +0000 Subject: [PATCH 1/3] allow jinja substitution in db template filenames --- tests/samples/schemas/multiple.ibek.ioc.schema.json | 11 +---------- tests/samples/schemas/objects.ibek.ioc.schema.json | 10 +--------- tests/samples/schemas/utils.ibek.ioc.schema.json | 9 +-------- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/tests/samples/schemas/multiple.ibek.ioc.schema.json b/tests/samples/schemas/multiple.ibek.ioc.schema.json index da1c4d461..25f48fa0e 100644 --- a/tests/samples/schemas/multiple.ibek.ioc.schema.json +++ b/tests/samples/schemas/multiple.ibek.ioc.schema.json @@ -238,16 +238,7 @@ "entities": { "description": "List of entities this IOC instantiates", "items": { - "discriminator": { - "mapping": { - "module.AllObject": "#/$defs/module_AllObject", - "object_module.Consumer": "#/$defs/object_module_Consumer", - "object_module.ConsumerTwo": "#/$defs/object_module_ConsumerTwo", - "object_module.RefObject": "#/$defs/object_module_RefObject" - }, - "propertyName": "type" - }, - "oneOf": [ + "anyOf": [ { "$ref": "#/$defs/object_module_RefObject" }, diff --git a/tests/samples/schemas/objects.ibek.ioc.schema.json b/tests/samples/schemas/objects.ibek.ioc.schema.json index d01197a9d..bd5e8f802 100644 --- a/tests/samples/schemas/objects.ibek.ioc.schema.json +++ b/tests/samples/schemas/objects.ibek.ioc.schema.json @@ -119,15 +119,7 @@ "entities": { "description": "List of entities this IOC instantiates", "items": { - "discriminator": { - "mapping": { - "object_module.Consumer": "#/$defs/object_module_Consumer", - "object_module.ConsumerTwo": "#/$defs/object_module_ConsumerTwo", - "object_module.RefObject": "#/$defs/object_module_RefObject" - }, - "propertyName": "type" - }, - "oneOf": [ + "anyOf": [ { "$ref": "#/$defs/object_module_RefObject" }, diff --git a/tests/samples/schemas/utils.ibek.ioc.schema.json b/tests/samples/schemas/utils.ibek.ioc.schema.json index 7839bf7e3..a13b3d8c1 100644 --- a/tests/samples/schemas/utils.ibek.ioc.schema.json +++ b/tests/samples/schemas/utils.ibek.ioc.schema.json @@ -82,14 +82,7 @@ "entities": { "description": "List of entities this IOC instantiates", "items": { - "discriminator": { - "mapping": { - "epics.InterruptVectorVME": "#/$defs/epics_InterruptVectorVME", - "epics.InterruptVectorVME2": "#/$defs/epics_InterruptVectorVME2" - }, - "propertyName": "type" - }, - "oneOf": [ + "anyOf": [ { "$ref": "#/$defs/epics_InterruptVectorVME" }, From e83396323d23cc64cbf20f63eb7e1c3bf270671d Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Mon, 6 Nov 2023 20:43:54 +0000 Subject: [PATCH 2/3] pin pydantic --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b8df56198..ee01cd3f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ ] description = "IOC Builder for EPICS and Kubernetes" dependencies = [ - "pydantic", + "pydantic==2.3.0", "typer", "ruamel.yaml", "jinja2", From 8383bdb6e12aa2291d1052ec987228eb479f560f Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Mon, 6 Nov 2023 20:50:57 +0000 Subject: [PATCH 3/3] add jinja render of db template filenames --- src/ibek/render_db.py | 2 ++ tests/samples/outputs/all.ioc.subst | 7 +++++++ tests/samples/yaml/all.ibek.support.yaml | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/ibek/render_db.py b/src/ibek/render_db.py index efe0ba13b..51a1695f4 100644 --- a/src/ibek/render_db.py +++ b/src/ibek/render_db.py @@ -28,6 +28,8 @@ def add_row(self, filename: str, args: Dict[str, Any], entity: Entity) -> None: Adding a new template file if it does not already exist. Convert all arguments to strings. """ + filename = render_with_utils(dict(entity), filename) + if filename not in self.render_templates: # for new filenames create a new RenderDbTemplate entry headings = [str(i) for i in list(args.keys())] diff --git a/tests/samples/outputs/all.ioc.subst b/tests/samples/outputs/all.ioc.subst index 808a99c20..13ad05aaa 100644 --- a/tests/samples/outputs/all.ioc.subst +++ b/tests/samples/outputs/all.ioc.subst @@ -16,6 +16,13 @@ pattern { "AllObject Two", "Ref1", "1.0", "True" } } +file "jinjified1.db" { +pattern + { "name" } + { "AllObject One" } + { "AllObject Two" } +} + file "test.db" { pattern { "name", "ip", "value" } diff --git a/tests/samples/yaml/all.ibek.support.yaml b/tests/samples/yaml/all.ibek.support.yaml index 9690fc2a3..b6f5dcf27 100644 --- a/tests/samples/yaml/all.ibek.support.yaml +++ b/tests/samples/yaml/all.ibek.support.yaml @@ -115,3 +115,6 @@ defs: my_object: my_float: my_bool: + - file: jinjified{{ my_int }}.db + args: + name: