-
Notifications
You must be signed in to change notification settings - Fork 10
/
asdf_dataclass.py.jinja
39 lines (30 loc) · 1.03 KB
/
asdf_dataclass.py.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from dataclasses import dataclass
from typing import List # noqa: F401
from weldx.asdf.types import WeldxType
from weldx.asdf.utils import drop_none_attr
{% for lib in lib_imports -%}
import {{ lib }}
{% endfor -%}
__all__ = ["{{class_name}}","{{class_name}}Type"]
@dataclass
class {{class_name}}:
"""<TODO CLASS DOCSTRING>"""
{% for prop, dtype in zip(properties,property_types) -%}
{{ prop }}: {{ dtype }}{%- if prop not in required %} = None{%- endif %}
{% endfor %}
class {{class_name}}Type(WeldxType):
"""<TODO ASDF TYPE DOCSTRING>"""
name = "{{ asdf_name }}"
version = "{{ asdf_version }}"
types = [{{ class_name }}]
requires = ["weldx"]
handle_dynamic_subclasses = True
@classmethod
def to_tree(cls, node: {{ class_name }}, ctx):
"""convert to tagged tree and remove all None entries from node dictionary"""
tree = drop_none_attr(node)
return tree
@classmethod
def from_tree(cls, tree, ctx):
obj = {{ class_name }}(**tree)
return obj