Skip to content

Commit

Permalink
model.base: Rename ModelingKind to ModellingKind (#104)
Browse files Browse the repository at this point in the history
In version 3.0 the Enum ModelingKind has been
renamed to ModellingKind.

This renames the class definition and all
its occurences in code and documentation.
  • Loading branch information
s-heppner committed Aug 24, 2023
1 parent d360723 commit 12156ca
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 41 deletions.
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'}
MODELLING_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()}
MODELLING_KIND_INVERSE: Dict[str, model.ModellingKind] = {v: k for k, v in MODELLING_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/aasJSONSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@
"type": "object",
"properties": {
"kind": {
"$ref": "#/definitions/ModelingKind"
"$ref": "#/definitions/ModellingKind"
}
}
},
Expand Down Expand Up @@ -811,7 +811,7 @@
"SubmodelElementList"
]
},
"ModelingKind": {
"ModellingKind": {
"type": "string",
"enum": [
"Instance",
Expand Down
6 changes: 3 additions & 3 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from typing import Dict, Callable, TypeVar, Type, List, IO, Optional, Set

from basyx.aas import model
from .._generic import MODELING_KIND_INVERSE, ASSET_KIND_INVERSE, KEY_TYPES_INVERSE, ENTITY_TYPES_INVERSE, \
from .._generic import MODELLING_KIND_INVERSE, ASSET_KIND_INVERSE, KEY_TYPES_INVERSE, ENTITY_TYPES_INVERSE, \
IEC61360_DATA_TYPES_INVERSE, IEC61360_LEVEL_TYPES_INVERSE, KEY_TYPES_CLASSES_INVERSE, REFERENCE_TYPES_INVERSE, \
DIRECTION_INVERSE, STATE_OF_EVENT_INVERSE, QUALIFIER_KIND_INVERSE

Expand Down 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 MODELLING_KIND_INVERSE[_get_ts(dct, "kind", str)] if 'kind' in dct else model.ModellingKind.INSTANCE

# #############################################################################
# Helper Constructor Methods starting from here
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/adapter/json/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ 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:
data['kind'] = _generic.MODELING_KIND[obj.kind]
if obj.kind is model.ModellingKind.TEMPLATE:
data['kind'] = _generic.MODELLING_KIND[obj.kind]
if isinstance(obj, model.Qualifiable) and not cls.stripped:
if obj.qualifier:
data['qualifiers'] = list(obj.qualifier)
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/adapter/xml/AAS.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
</xs:group>
<xs:group name="hasKind">
<xs:sequence>
<xs:element name="kind" type="modelingKind_t" minOccurs="0" maxOccurs="1"/>
<xs:element name="kind" type="modellingKind_t" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:group>
<xs:group name="hasKind_choice">
Expand Down Expand Up @@ -1110,7 +1110,7 @@
<xs:group ref="levelType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="modelingKind_t">
<xs:simpleType name="modellingKind_t">
<xs:restriction base="xs:string">
<xs:enumeration value="Template"/>
<xs:enumeration value="Instance"/>
Expand Down
18 changes: 9 additions & 9 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import enum

from typing import Any, Callable, Dict, IO, Iterable, Optional, Set, Tuple, Type, TypeVar
from .._generic import XML_NS_AAS, MODELING_KIND_INVERSE, ASSET_KIND_INVERSE, KEY_TYPES_INVERSE, ENTITY_TYPES_INVERSE, \
IEC61360_DATA_TYPES_INVERSE, IEC61360_LEVEL_TYPES_INVERSE, KEY_TYPES_CLASSES_INVERSE, REFERENCE_TYPES_INVERSE, \
DIRECTION_INVERSE, STATE_OF_EVENT_INVERSE, QUALIFIER_KIND_INVERSE
from .._generic import XML_NS_AAS, MODELLING_KIND_INVERSE, ASSET_KIND_INVERSE, KEY_TYPES_INVERSE, \
ENTITY_TYPES_INVERSE, IEC61360_DATA_TYPES_INVERSE, IEC61360_LEVEL_TYPES_INVERSE, KEY_TYPES_CLASSES_INVERSE, \
REFERENCE_TYPES_INVERSE, DIRECTION_INVERSE, STATE_OF_EVENT_INVERSE, QUALIFIER_KIND_INVERSE

NS_AAS = XML_NS_AAS

Expand Down 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.
Returns the modelling kind of an element with the default value INSTANCE, if none specified.
:param element: The xml element.
:return: The modeling kind of the element.
:return: The modelling kind of the element.
"""
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"), MODELLING_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 @@ -1003,7 +1003,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
4 changes: 2 additions & 2 deletions basyx/aas/adapter/xml/xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ 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
# then modelling-kind is Instance
elm.append(_generate_element(name=NS_AAS + "kind", text="Instance"))
if isinstance(obj, model.HasSemantics):
if obj.semantic_id:
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 @@ -206,7 +206,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 @@ -330,7 +330,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 @@ -728,7 +728,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 @@ -288,7 +288,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 @@ -297,7 +297,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
2 changes: 1 addition & 1 deletion basyx/aas/model/aas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AssetInformation:
:ivar asset_kind: Denotes whether the Asset is of :class:`~aas.model.base.AssetKind` "TYPE" or "INSTANCE".
Default is "INSTANCE".
:ivar global_asset_id: :class:`~aas.model.base.Identifier` modeling the identifier of the asset the AAS is
:ivar global_asset_id: :class:`~aas.model.base.Identifier` modelling the identifier of the asset the AAS is
representing.
This attribute is required as soon as the AAS is exchanged via partners in the
life cycle of the asset. In a first phase of the life cycle the asset might not yet have a
Expand Down
12 changes: 6 additions & 6 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,
*Note:* An :attr:`~.ModellingKind.INSTANCE` 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).
: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 @@ -1425,12 +1425,12 @@ class HasKind(metaclass=abc.ABCMeta):
<<abstract>>
:ivar _kind: Kind of the element: either type or instance. Default = :attr:`~ModelingKind.INSTANCE`.
:ivar _kind: Kind of the element: either type or instance. Default = :attr:`~ModellingKind.INSTANCE`.
"""
@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
6 changes: 3 additions & 3 deletions test/adapter/xml/test_xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_invalid_boolean(self) -> None:
""")
self._assertInExceptionAndLog(xml, "False", ValueError, logging.ERROR)

def test_no_modeling_kind(self) -> None:
def test_no_modelling_kind(self) -> None:
xml = _xml_wrap("""
<aas:submodels>
<aas:submodel>
Expand All @@ -140,11 +140,11 @@ def test_no_modeling_kind(self) -> None:
""")
# should get parsed successfully
object_store = read_aas_xml_file(io.BytesIO(xml.encode("utf-8")), failsafe=False)
# modeling kind should default to INSTANCE
# modelling kind should default to INSTANCE
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

0 comments on commit 12156ca

Please sign in to comment.