Skip to content

Commit

Permalink
attempt to manage cyclic references across multiple files
Browse files Browse the repository at this point in the history
this is not working unfortunately (today); a similar approach may work in the future when superclass inherited type hints may work as well (probably python 3.13+)

Signed-off-by: Federico M. Facca <[email protected]>
  • Loading branch information
chicco785 committed Oct 16, 2023
1 parent cd22874 commit 1bd90dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions modernpython/langPack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_class_location(class_name, class_map, version):
# Check if the current class has a parent class
if class_map[class_name].superClass():
if class_map[class_name].superClass() in class_map:
return "cimpy." + version + "." + class_map[class_name].superClass()
return "modernpython." + version + "." + class_map[class_name].superClass()
elif class_map[class_name].superClass() == "Base" or class_map[class_name].superClass() == None:
return location(version)
else:
Expand All @@ -53,7 +53,7 @@ def _compute_data_type(attribute):

if "range" in attribute:
# return "'"+attribute["range"].split("#")[1]+"'"
return attribute["range"].split("#")[1]
return "'"+attribute["range"].split("#")[1]+"'"
if "dataType" in attribute and "class_name" in attribute:
# for whatever weird reason String is not created as class from CIMgen
if is_primitive_class(attribute["class_name"]) or attribute["class_name"] == "String":
Expand Down Expand Up @@ -84,7 +84,7 @@ def _compute_data_type(attribute):
if is_cim_data_type_class(attribute["class_name"]):
return "float"
# this is for example the case for 'StreetAddress.streetDetail'
return attribute["dataType"].split("#")[1]
return "'"+attribute["dataType"].split("#")[1]+"'"

def _ends_with_s(attribute_name):
return attribute_name.endswith("s")
Expand Down
8 changes: 6 additions & 2 deletions modernpython/templates/cimpy_class_template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ from functools import cached_property
from typing import Optional, List
from pydantic import Field, field_validator
import uuid
from pydantic.dataclasses import dataclass
from datetime import date, datetime, time
from pydantic.dataclasses import dataclass, rebuild_dataclass
from .Base import DataclassConfig, Profile
from .util import cyclic_references_validator
from .{{sub_class_of}} import {{sub_class_of}}
{{#setImports}}{{attributes}}{{/setImports}}

@dataclass(config=DataclassConfig)
class {{class_name}}({{sub_class_of}}):
Expand Down Expand Up @@ -46,3 +46,7 @@ class {{class_name}}({{sub_class_of}}):
where this element can be found.
"""
return { {{#class_origin}}Profile.{{origin}}, {{/class_origin}} }

{{#setImports}}{{attributes}}{{/setImports}}

rebuild_dataclass({{class_name}})

0 comments on commit 1bd90dd

Please sign in to comment.