From e681a4fa4e272ef33a6cdbac1712a87ed23a0ae8 Mon Sep 17 00:00:00 2001 From: HUG0-D Date: Tue, 19 Nov 2024 10:19:13 +0100 Subject: [PATCH] Enum class generation using chevron Signed-off-by: HUG0-D --- cimgen/languages/modernpython/lang_pack.py | 15 --------------- .../modernpython/templates/enum_template.mustache | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/cimgen/languages/modernpython/lang_pack.py b/cimgen/languages/modernpython/lang_pack.py index 9b368dc1..710800fb 100644 --- a/cimgen/languages/modernpython/lang_pack.py +++ b/cimgen/languages/modernpython/lang_pack.py @@ -1,7 +1,6 @@ import logging import os import re -import ast from distutils.dir_util import copy_tree from pathlib import Path from importlib.resources import files @@ -149,19 +148,6 @@ def _set_attribute_class(text, render) -> str: return attribute_class -# called by chevron, text contains the label {{dataType}}, which is evaluated by the renderer (see class template) -def _set_instances(text, render): - instance = None - instance = ast.literal_eval(render(text).replace(""", '"')) - if "label" in instance: - value = instance["label"] + ' = "' + instance["label"] + '"' - if "comment" in instance: - value += " # " + instance["comment"] + " noqa: E501" - return value - else: - return "" - - def run_template(output_path, class_details): if class_details["is_a_primitive_class"]: # Primitives are never used in the in memory representation but only for @@ -175,7 +161,6 @@ def run_template(output_path, class_details): class_details.update(_set_datatype_attributes(class_details["attributes"])) elif class_details["is_an_enum_class"]: template = enum_template_file - class_details["setInstances"] = _set_instances else: template = class_template_file class_details["setDefault"] = _set_default diff --git a/cimgen/languages/modernpython/templates/enum_template.mustache b/cimgen/languages/modernpython/templates/enum_template.mustache index 0622b9b4..d0b3826c 100644 --- a/cimgen/languages/modernpython/templates/enum_template.mustache +++ b/cimgen/languages/modernpython/templates/enum_template.mustache @@ -7,9 +7,9 @@ from enum import Enum class {{class_name}}(str, Enum): """ - {{{class_comment}}} + {{{class_comment}}} # noqa: E501 """ {{#enum_instances}} - {{#setInstances}}{{.}}{{/setInstances}} + {{label}} = "{{label}}"{{#comment}} # {{comment}}{{/comment}} # noqa: E501 {{/enum_instances}}