Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.base: Rename ModelingKind to ModellingKind #104

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions basyx/aas/adapter/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
XML_NS_MAP = {"aas": "https://admin-shell.io/aas/3/0"}
XML_NS_AAS = "{" + XML_NS_MAP["aas"] + "}"

MODELING_KIND: Dict[model.ModelingKind, str] = {
model.ModelingKind.TEMPLATE: 'Template',
model.ModelingKind.INSTANCE: 'Instance'}
MODELING_KIND: Dict[model.ModellingKind, str] = {
model.ModellingKind.TEMPLATE: 'Template',
model.ModellingKind.INSTANCE: 'Instance'}

ASSET_KIND: Dict[model.AssetKind, str] = {
model.AssetKind.TYPE: 'Type',
Expand Down Expand Up @@ -92,7 +92,7 @@
model.base.IEC61360LevelType.MAX: 'max',
}

MODELING_KIND_INVERSE: Dict[str, model.ModelingKind] = {v: k for k, v in MODELING_KIND.items()}
MODELING_KIND_INVERSE: Dict[str, model.ModellingKind] = {v: k for k, v in MODELING_KIND.items()}
ASSET_KIND_INVERSE: Dict[str, model.AssetKind] = {v: k for k, v in ASSET_KIND.items()}
QUALIFIER_KIND_INVERSE: Dict[str, model.QualifierKind] = {v: k for k, v in QUALIFIER_KIND.items()}
DIRECTION_INVERSE: Dict[str, model.Direction] = {v: k for k, v in DIRECTION.items()}
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ def _amend_abstract_attributes(cls, obj: object, dct: Dict[str, object]) -> None
obj.extension.add(cls._construct_extension(extension))

@classmethod
def _get_kind(cls, dct: Dict[str, object]) -> model.ModelingKind:
def _get_kind(cls, dct: Dict[str, object]) -> model.ModellingKind:
"""
Utility method to get the kind of an HasKind object from its JSON representation.

:param dct: The object's dict representation from JSON
:return: The object's `kind` value
"""
return MODELING_KIND_INVERSE[_get_ts(dct, "kind", str)] if 'kind' in dct else model.ModelingKind.INSTANCE
return MODELING_KIND_INVERSE[_get_ts(dct, "kind", str)] if 'kind' in dct else model.ModellingKind.INSTANCE

# #############################################################################
# Helper Constructor Methods starting from here
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/adapter/json/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _abstract_classes_to_json(cls, obj: object) -> Dict[str, object]:
if obj.supplemental_semantic_id:
data['supplementalSemanticIds'] = list(obj.supplemental_semantic_id)
if isinstance(obj, model.HasKind):
if obj.kind is model.ModelingKind.TEMPLATE:
if obj.kind is model.ModellingKind.TEMPLATE:
data['kind'] = _generic.MODELING_KIND[obj.kind]
if isinstance(obj, model.Qualifiable) and not cls.stripped:
if obj.qualifier:
Expand Down
8 changes: 4 additions & 4 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ def _child_text_mandatory_mapped(parent: etree.Element, child_tag: str, dct: Dic
return _get_text_mandatory_mapped(_get_child_mandatory(parent, child_tag), dct)


def _get_modeling_kind(element: etree.Element) -> model.ModelingKind:
def _get_kind(element: etree.Element) -> model.ModellingKind:
"""
Returns the modeling kind of an element with the default value INSTANCE, if none specified.
s-heppner marked this conversation as resolved.
Show resolved Hide resolved

:param element: The xml element.
:return: The modeling kind of the element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here another

"""
modeling_kind = _get_text_mapped_or_none(element.find(NS_AAS + "kind"), MODELING_KIND_INVERSE)
return modeling_kind if modeling_kind is not None else model.ModelingKind.INSTANCE
modelling_kind = _get_text_mapped_or_none(element.find(NS_AAS + "kind"), MODELING_KIND_INVERSE)
return modelling_kind if modelling_kind is not None else model.ModellingKind.INSTANCE


def _expect_reference_type(element: etree.Element, expected_type: Type[model.Reference]) -> None:
Expand Down Expand Up @@ -999,7 +999,7 @@ def construct_submodel(cls, element: etree.Element, object_class=model.Submodel,
-> model.Submodel:
submodel = object_class(
_child_text_mandatory(element, NS_AAS + "id"),
kind=_get_modeling_kind(element)
kind=_get_kind(element)
)
if not cls.stripped:
submodel_elements = element.find(NS_AAS + "submodelElements")
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/adapter/xml/xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def abstract_classes_to_xml(tag: str, obj: object) -> etree.Element:
elm.append(administrative_information_to_xml(obj.administration))
elm.append(_generate_element(name=NS_AAS + "id", text=obj.id))
if isinstance(obj, model.HasKind):
if obj.kind is model.ModelingKind.TEMPLATE:
if obj.kind is model.ModellingKind.TEMPLATE:
elm.append(_generate_element(name=NS_AAS + "kind", text="Template"))
else:
# then modeling-kind is Instance
Expand Down
6 changes: 3 additions & 3 deletions basyx/aas/examples/data/example_aas.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def create_example_asset_identification_submodel() -> model.Submodel:
value='http://acplt.org/SubmodelTemplates/AssetIdentification'),),
model.Submodel),
qualifier=(),
kind=model.ModelingKind.INSTANCE,
kind=model.ModellingKind.INSTANCE,
extension=(),
supplemental_semantic_id=(),
embedded_data_specifications=()
Expand Down Expand Up @@ -318,7 +318,7 @@ def create_example_bill_of_material_submodel() -> model.Submodel:
value='http://acplt.org/SubmodelTemplates/BillOfMaterial'),),
model.Submodel),
qualifier=(),
kind=model.ModelingKind.INSTANCE,
kind=model.ModellingKind.INSTANCE,
extension=(),
supplemental_semantic_id=(),
embedded_data_specifications=()
Expand Down Expand Up @@ -708,7 +708,7 @@ def create_example_submodel() -> model.Submodel:
value='http://acplt.org/SubmodelTemplates/'
'ExampleSubmodel'),)),
qualifier=(),
kind=model.ModelingKind.INSTANCE,
kind=model.ModellingKind.INSTANCE,
extension=(),
supplemental_semantic_id=(),
embedded_data_specifications=(_embedded_data_specification_physical_unit,)
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/examples/data/example_aas_missing_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def create_example_submodel() -> model.Submodel:
value='http://acplt.org/SubmodelTemplates/'
'ExampleSubmodel'),)),
qualifier=(),
kind=model.ModelingKind.INSTANCE)
kind=model.ModellingKind.INSTANCE)
return submodel


Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/examples/data/example_submodel_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def create_example_submodel_template() -> model.Submodel:
value='http://acplt.org/SubmodelTemplates/'
'ExampleSubmodel'),)),
qualifier=(),
kind=model.ModelingKind.TEMPLATE)
kind=model.ModellingKind.TEMPLATE)
return submodel


Expand Down
8 changes: 4 additions & 4 deletions basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ class EntityType(Enum):


@unique
class ModelingKind(Enum):
class ModellingKind(Enum):
"""
Enumeration for denoting whether an element is a type or an instance.
*Note:* An :attr:`~.ModelingKind.INSTANCE` becomes an individual entity of a template, for example a device model,
s-heppner marked this conversation as resolved.
Show resolved Hide resolved
by defining specific property values.

*Note:* In an object oriented view, an instance denotes an object of a template (class).
*Note:* In an object-oriented view, an instance denotes an object of a template (class).

:cvar TEMPLATE: Software element which specifies the common attributes shared by all instances of the template
:cvar INSTANCE: concrete, clearly identifiable component of a certain template.
*Note:* It becomes an individual entity of a template, for example a device model, by defining
specific property values.
*Note:* In an object oriented view, an instance denotes an object of a template (class).
*Note:* In an object-oriented view, an instance denotes an object of a template (class).
"""

TEMPLATE = 0
Expand Down Expand Up @@ -1410,7 +1410,7 @@ class HasKind(metaclass=abc.ABCMeta):
@abc.abstractmethod
def __init__(self):
super().__init__()
self._kind: ModelingKind = ModelingKind.INSTANCE
self._kind: ModellingKind = ModellingKind.INSTANCE

@property
def kind(self):
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/model/submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self,
administration: Optional[base.AdministrativeInformation] = None,
semantic_id: Optional[base.Reference] = None,
qualifier: Iterable[base.Qualifier] = (),
kind: base.ModelingKind = base.ModelingKind.INSTANCE,
kind: base.ModellingKind = base.ModellingKind.INSTANCE,
extension: Iterable[base.Extension] = (),
supplemental_semantic_id: Iterable[base.Reference] = (),
embedded_data_specifications: Iterable[base.EmbeddedDataSpecification] = ()):
Expand All @@ -145,7 +145,7 @@ def __init__(self,
self.administration: Optional[base.AdministrativeInformation] = administration
self.semantic_id: Optional[base.Reference] = semantic_id
self.qualifier = base.NamespaceSet(self, [("type", True)], qualifier)
self._kind: base.ModelingKind = kind
self._kind: base.ModellingKind = kind
self.extension = base.NamespaceSet(self, [("name", True)], extension)
self.supplemental_semantic_id: base.ConstrainedList[base.Reference] = \
base.ConstrainedList(supplemental_semantic_id)
Expand Down
2 changes: 1 addition & 1 deletion test/adapter/xml/test_xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_no_modeling_kind(self) -> None:
submodel = object_store.pop()
self.assertIsInstance(submodel, model.Submodel)
assert isinstance(submodel, model.Submodel) # to make mypy happy
self.assertEqual(submodel.kind, model.ModelingKind.INSTANCE)
self.assertEqual(submodel.kind, model.ModellingKind.INSTANCE)

def test_reference_kind_mismatch(self) -> None:
xml = _xml_wrap("""
Expand Down
Loading