Skip to content

Commit

Permalink
Enum class generation using chevron
Browse files Browse the repository at this point in the history
Signed-off-by: HUG0-D <[email protected]>
  • Loading branch information
HUG0-D committed Nov 19, 2024
1 parent 58e0c21 commit e681a4f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions cimgen/languages/modernpython/lang_pack.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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("&quot;", '"'))
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit e681a4f

Please sign in to comment.