From b44074515996b263554b598f16d6a5013cbf8d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 22 Dec 2023 04:57:00 +0100 Subject: [PATCH] fix pycodestyle warnings --- basyx/aas/adapter/aasx.py | 63 +++++++++---------- basyx/aas/backend/__init__.py | 4 +- basyx/aas/backend/backends.py | 24 +++---- basyx/aas/backend/couchdb.py | 16 +++-- basyx/aas/backend/local_file.py | 11 ++-- basyx/aas/examples/data/example_aas.py | 4 +- .../data/example_aas_mandatory_attributes.py | 4 +- .../data/example_aas_missing_attributes.py | 10 +-- basyx/aas/model/__init__.py | 4 +- basyx/aas/model/aas.py | 4 +- basyx/aas/model/base.py | 26 ++++---- basyx/aas/model/concept.py | 4 +- basyx/aas/model/datatypes.py | 11 ++-- basyx/aas/model/provider.py | 8 +-- basyx/aas/model/submodel.py | 35 ++++++----- basyx/aas/util/identification.py | 12 ++-- basyx/aas/util/traversal.py | 6 +- 17 files changed, 128 insertions(+), 118 deletions(-) diff --git a/basyx/aas/adapter/aasx.py b/basyx/aas/adapter/aasx.py index 76317c8df..1f69046b7 100644 --- a/basyx/aas/adapter/aasx.py +++ b/basyx/aas/adapter/aasx.py @@ -119,20 +119,19 @@ def read_into(self, object_store: model.AbstractObjectStore, This function does the main job of reading the AASX file's contents. It traverses the relationships within the package to find AAS JSON or XML parts, parses them and adds the contained AAS objects into the provided - `object_store`. While doing so, it searches all parsed :class:`Submodels ` for - :class:`~basyx.aas.model.submodel.File` objects to extract the supplementary - files. The referenced supplementary files are added to the given `file_store` and the - :class:`~basyx.aas.model.submodel.File` objects' values are updated with the absolute name of the supplementary file - to allow for robust resolution the file within the - `file_store` later. + `object_store`. While doing so, it searches all parsed :class:`Submodels ` + for :class:`~basyx.aas.model.submodel.File` objects to extract the supplementary files. The referenced + supplementary files are added to the given `file_store` and the :class:`~basyx.aas.model.submodel.File` + objects' values are updated with the absolute name of the supplementary file to allow for robust resolution the + file within the `file_store` later. :param object_store: An :class:`ObjectStore ` to add the AAS objects from the AASX file to :param file_store: A :class:`SupplementaryFileContainer <.AbstractSupplementaryFileContainer>` to add the embedded supplementary files to :param override_existing: If `True`, existing objects in the object store are overridden with objects from the - AASX that have the same :class:`~basyx.aas.model.base.Identifier`. Default behavior is to skip those objects from - the AASX. + AASX that have the same :class:`~basyx.aas.model.base.Identifier`. Default behavior is to skip those objects + from the AASX. :return: A set of the :class:`Identifiers ` of all :class:`~basyx.aas.model.base.Identifiable` objects parsed from the AASX file """ @@ -323,19 +322,18 @@ def write_aas(self, write_json: bool = False) -> None: """ Convenience method to write one or more - :class:`AssetAdministrationShells ` with all included and referenced - objects to the AASX package according to the part name conventions from DotAAS. - - This method takes the AASs' :class:`Identifiers ` (as `aas_ids`) to retrieve the - AASs from the given object_store. - :class:`References ` to :class:`Submodels ` and - :class:`ConceptDescriptions ` (via semanticId attributes) are also - resolved using the - `object_store`. All of these objects are written to an aas-spec part `/aasx/data.xml` or `/aasx/data.json` in - the AASX package, compliant to the convention presented in "Details of the Asset Administration Shell". - Supplementary files which are referenced by a :class:`~basyx.aas.model.submodel.File` object in any of the - :class:`Submodels ` are also added to the AASX - package. + :class:`AssetAdministrationShells ` with all included + and referenced objects to the AASX package according to the part name conventions from DotAAS. + + This method takes the AASs' :class:`Identifiers ` (as `aas_ids`) to retrieve + the AASs from the given object_store. + :class:`References ` to :class:`Submodels ` + and :class:`ConceptDescriptions ` (via semanticId attributes) are + also resolved using the `object_store`. All of these objects are written to an aas-spec part `/aasx/data.xml` + or `/aasx/data.json` in the AASX package, compliant to the convention presented in + "Details of the Asset Administration Shell". Supplementary files which are referenced by a + :class:`~basyx.aas.model.submodel.File` object in any of the + :class:`Submodels ` are also added to the AASX package. This method uses `write_all_aas_objects()` to write the AASX part. @@ -351,16 +349,18 @@ def write_aas(self, :param aas_ids: :class:`~basyx.aas.model.base.Identifier` or Iterable of :class:`Identifiers ` of the AAS(s) to be written to the AASX file :param object_store: :class:`ObjectStore ` to retrieve the - :class:`~basyx.aas.model.base.Identifiable` AAS objects (:class:`~basyx.aas.model.aas.AssetAdministrationShell`, + :class:`~basyx.aas.model.base.Identifiable` AAS objects + (:class:`~basyx.aas.model.aas.AssetAdministrationShell`, :class:`~basyx.aas.model.concept.ConceptDescription` and :class:`~basyx.aas.model.submodel.Submodel`) from :param file_store: :class:`SupplementaryFileContainer <~.AbstractSupplementaryFileContainer>` to retrieve supplementary files from, which are referenced by :class:`~basyx.aas.model.submodel.File` objects - :param write_json: If `True`, JSON parts are created for the AAS and each :class:`~basyx.aas.model.submodel.Submodel` - in the AASX package file instead of XML parts. Defaults to `False`. + :param write_json: If `True`, JSON parts are created for the AAS and each + :class:`~basyx.aas.model.submodel.Submodel` in the AASX package file instead of XML parts. + Defaults to `False`. :raises KeyError: If one of the AAS could not be retrieved from the object store (unresolvable :class:`Submodels ` and - :class:`ConceptDescriptions ` are skipped, logging a warning/info - message) + :class:`ConceptDescriptions ` are skipped, logging a + warning/info message) :raises TypeError: If one of the given AAS ids does not resolve to an AAS (but another :class:`~basyx.aas.model.base.Identifiable` object) """ @@ -428,10 +428,9 @@ def write_aas_objects(self, """ A thin wrapper around :meth:`write_all_aas_objects` to ensure downwards compatibility - This method takes the AAS's :class:`~basyx.aas.model.base.Identifier` (as `aas_id`) to retrieve it from the given - object_store. If the list - of written objects includes :class:`aas.model.submodel.Submodel` objects, Supplementary files which are - referenced by :class:`~basyx.aas.model.submodel.File` objects within + This method takes the AAS's :class:`~basyx.aas.model.base.Identifier` (as `aas_id`) to retrieve it + from the given object_store. If the list of written objects includes :class:`aas.model.submodel.Submodel` + objects, Supplementary files which are referenced by :class:`~basyx.aas.model.submodel.File` objects within those submodels, are also added to the AASX package. .. attention:: @@ -442,8 +441,8 @@ def write_aas_objects(self, :param part_name: Name of the Part within the AASX package to write the files to. Must be a valid ECMA376-2 part name and unique within the package. The extension of the part should match the data format (i.e. '.json' if `write_json` else '.xml'). - :param object_ids: A list of :class:`Identifiers ` of the objects to be written to - the AASX package. Only these :class:`~basyx.aas.model.base.Identifiable` objects (and included + :param object_ids: A list of :class:`Identifiers ` of the objects to be written + to the AASX package. Only these :class:`~basyx.aas.model.base.Identifiable` objects (and included :class:`~basyx.aas.model.base.Referable` objects) are written to the package. :param object_store: The objects store to retrieve the :class:`~basyx.aas.model.base.Identifiable` objects from :param file_store: The :class:`SupplementaryFileContainer ` diff --git a/basyx/aas/backend/__init__.py b/basyx/aas/backend/__init__.py index 2d53e2668..12fdcbe89 100644 --- a/basyx/aas/backend/__init__.py +++ b/basyx/aas/backend/__init__.py @@ -1,7 +1,7 @@ """ This module implements a standardized way of integrating data from existing systems into AAS objects. To achieve this, the abstract :class:`~basyx.aas.backend.backends.Backend` class implements the classmethods -:meth:`~basyx.aas.backend.backends.Backend.update_object` and :meth:`~basyx.aas.backend.backends.Backend.commit_object`, which every -implementation of a backend needs to overwrite. For a tutorial on how to implement a backend, see +:meth:`~basyx.aas.backend.backends.Backend.update_object` and :meth:`~basyx.aas.backend.backends.Backend.commit_object`, +which every implementation of a backend needs to overwrite. For a tutorial on how to implement a backend, see :ref:`this tutorial ` """ diff --git a/basyx/aas/backend/backends.py b/basyx/aas/backend/backends.py index 4e94f7600..55bc1e337 100644 --- a/basyx/aas/backend/backends.py +++ b/basyx/aas/backend/backends.py @@ -15,9 +15,9 @@ Custom backends for additional types of data sources can be implemented by subclassing the `Backend` class and implementing the :meth:`~.Backend.commit_object` and :meth:`~.Backend.update_object` class methods. These are used -internally by the objects' :meth:`~basyx.aas.model.base.Referable.update` and :meth:`~basyx.aas.model.base.Referable.commit` -methods when the backend is applicable for the relevant source URI. Then, the Backend class -needs to be registered to handle update/commit requests for a specific URI schema, using +internally by the objects' :meth:`~basyx.aas.model.base.Referable.update` and +:meth:`~basyx.aas.model.base.Referable.commit` methods when the backend is applicable for the relevant source URI. +Then, the Backend class needs to be registered to handle update/commit requests for a specific URI schema, using :meth:`~aas.backend.backends.register_backend`. """ import abc @@ -35,8 +35,8 @@ class Backend(metaclass=abc.ABCMeta): Each Backend class is typically capable of synchronizing (updating/committing) objects with a type of external data source, identified by one or more source URI schemas. Custom backends for custom source URI schemas should inherit from this class and be registered via :meth:`~aas.backend.backends.register_backend`. to be used by Referable - object's :meth:`~basyx.aas.model.base.Referable.update` and :meth:`~basyx.aas.model.base.Referable.commit` methods when - required. + object's :meth:`~basyx.aas.model.base.Referable.update` and :meth:`~basyx.aas.model.base.Referable.commit` methods + when required. """ @classmethod @@ -86,13 +86,13 @@ def update_object(cls, Function (class method) to be called when an object shall be updated (local object updated with changes from the external data source) via this backend implementation. - It is automatically called by the :meth:`~basyx.aas.model.base.Referable.update` implementation, when the source URI - of the object or - the source URI one of its ancestors in the AAS object containment hierarchy include an URI schema for which this - backend has been registered. Both of the objects are passed to this function: the one which shall be update - (`updated_object`) and its ancestor with the relevant source URI (`store_object`). They may be the same, the - updated object has a source with the relevant schema itself. Additionally, the `relative_path` from the - `store_object` down to the `updated_object` is provided. + It is automatically called by the :meth:`~basyx.aas.model.base.Referable.update` implementation, + when the source URI of the object or the source URI one of its ancestors in the AAS object containment hierarchy + include an URI schema for which this backend has been registered. Both of the objects are passed + to this function: the one which shall be update (`updated_object`) and its ancestor with + the relevant source URI (`store_object`). They may be the same, the updated object has a source with + the relevant schema itself. Additionally, the `relative_path` from the `store_object` down to + the `updated_object` is provided. The backend MUST ensure to update at least the `updated_object` and all objects contained within it (if any) with any changes from the data source. It MAY additionally update other objects (i.e. the `store_object` and any diff --git a/basyx/aas/backend/couchdb.py b/basyx/aas/backend/couchdb.py index 2495451a0..7c23e77fb 100644 --- a/basyx/aas/backend/couchdb.py +++ b/basyx/aas/backend/couchdb.py @@ -5,7 +5,8 @@ # # SPDX-License-Identifier: MIT """ -This module adds the functionality of storing and retrieving :class:`~basyx.aas.model.base.Identifiable` objects in a CouchDB. +This module adds the functionality of storing and retrieving :class:`~basyx.aas.model.base.Identifiable` objects +in a CouchDB. The :class:`~.CouchDBBackend` takes care of updating and committing objects from and to the CouchDB, while the :class:`~CouchDBObjectStore` handles adding, deleting and otherwise managing the AAS objects in a specific CouchDB. @@ -181,7 +182,8 @@ def register_credentials(url: str, username: str, password: str): .. Warning:: Do not use this function, while other threads may be accessing the credentials via the - :class:`~.CouchDBObjectStore` or update or commit functions of :class:`~.basyx.aas.model.base.Referable` objects! + :class:`~.CouchDBObjectStore` or update or commit functions of :class:`~.basyx.aas.model.base.Referable` + objects! :param url: Toplevel URL :param username: Username to that CouchDB instance @@ -230,8 +232,8 @@ def delete_couchdb_revision(url: str): class CouchDBObjectStore(model.AbstractObjectStore): """ - An ObjectStore implementation for :class:`~basyx.aas.model.base.Identifiable` BaSyx Python SDK objects backed by a CouchDB - database server. + An ObjectStore implementation for :class:`~basyx.aas.model.base.Identifiable` BaSyx Python SDK objects backed + by a CouchDB database server. All methods of the `CouchDBObjectStore` are blocking, i.e. they stop the current thread's execution until they receive a response from the CouchDB server (or encounter a timeout). However, the `CouchDBObjectStore` objects are @@ -420,7 +422,8 @@ def __contains__(self, x: object) -> bool: Check if an object with the given :class:`~basyx.aas.model.base.Identifier` or the same :class:`~basyx.aas.model.base.Identifier` as the given object is contained in the CouchDB database - :param x: AAS object :class:`~basyx.aas.model.base.Identifier` or :class:`~basyx.aas.model.base.Identifiable` AAS object + :param x: AAS object :class:`~basyx.aas.model.base.Identifier` or :class:`~basyx.aas.model.base.Identifiable` + AAS object :return: `True` if such an object exists in the database, `False` otherwise :raises CouchDBError: If error occur during the request to the CouchDB server (see `_do_request()` for details) """ @@ -490,7 +493,8 @@ def _transform_id(identifier: model.Identifier, url_quote=True) -> str: def generate_source(self, identifiable: model.Identifiable): """ - Generates the source string for an :class:`~basyx.aas.model.base.Identifiable` object that is backed by the Couchdb + Generates the source string for an :class:`~basyx.aas.model.base.Identifiable` object that is backed + by the Couchdb :param identifiable: Identifiable object """ diff --git a/basyx/aas/backend/local_file.py b/basyx/aas/backend/local_file.py index 5f6b0b350..82a8169c4 100644 --- a/basyx/aas/backend/local_file.py +++ b/basyx/aas/backend/local_file.py @@ -5,8 +5,8 @@ # # SPDX-License-Identifier: MIT """ -This module adds the functionality of storing and retrieving :class:`~basyx.aas.model.base.Identifiable` objects in local -files. +This module adds the functionality of storing and retrieving :class:`~basyx.aas.model.base.Identifiable` objects +in local files. The :class:`~.LocalFileBackend` takes care of updating and committing objects from and to the files, while the :class:`~LocalFileObjectStore` handles adding, deleting and otherwise managing the AAS objects in a specific Directory. @@ -68,8 +68,8 @@ def commit_object(cls, class LocalFileObjectStore(model.AbstractObjectStore): """ - An ObjectStore implementation for :class:`~basyx.aas.model.base.Identifiable` BaSyx Python SDK objects backed by a local - file based local backend + An ObjectStore implementation for :class:`~basyx.aas.model.base.Identifiable` BaSyx Python SDK objects backed + by a local file based local backend """ def __init__(self, directory_path: str): """ @@ -176,7 +176,8 @@ def __contains__(self, x: object) -> bool: Check if an object with the given :class:`~basyx.aas.model.base.Identifier` or the same :class:`~basyx.aas.model.base.Identifier` as the given object is contained in the local file database - :param x: AAS object :class:`~basyx.aas.model.base.Identifier` or :class:`~basyx.aas.model.base.Identifiable` AAS object + :param x: AAS object :class:`~basyx.aas.model.base.Identifier` or :class:`~basyx.aas.model.base.Identifiable` + AAS object :return: `True` if such an object exists in the database, `False` otherwise """ if isinstance(x, model.Identifier): diff --git a/basyx/aas/examples/data/example_aas.py b/basyx/aas/examples/data/example_aas.py index f773a07ed..b5dd86405 100644 --- a/basyx/aas/examples/data/example_aas.py +++ b/basyx/aas/examples/data/example_aas.py @@ -66,8 +66,8 @@ def create_full_example() -> model.DictObjectStore: def create_example_asset_identification_submodel() -> model.Submodel: """ - Creates a :class:`~basyx.aas.model.submodel.Submodel` containing two :class:`~basyx.aas.model.submodel.Property` elements - according to 'Verwaltungssschale in der Praxis' + Creates a :class:`~basyx.aas.model.submodel.Submodel` containing two :class:`~basyx.aas.model.submodel.Property` + elements according to 'Verwaltungssschale in der Praxis' https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/2019-verwaltungsschale-in-der-praxis.html :return: example asset identification submodel diff --git a/basyx/aas/examples/data/example_aas_mandatory_attributes.py b/basyx/aas/examples/data/example_aas_mandatory_attributes.py index b1d9dfc1a..3485c13b8 100644 --- a/basyx/aas/examples/data/example_aas_mandatory_attributes.py +++ b/basyx/aas/examples/data/example_aas_mandatory_attributes.py @@ -6,8 +6,8 @@ # SPDX-License-Identifier: MIT """ Module for the creation of an :class:`ObjectStore ` with an example -:class:`~basyx.aas.model.aas.AssetAdministrationShell` and example :class:`Submodels ` -and a :class:`~aas.model.concept.ConceptDictionary` containing an +:class:`~basyx.aas.model.aas.AssetAdministrationShell` and example +:class:`Submodels ` and a :class:`~aas.model.concept.ConceptDictionary` containing an example :class:`~basyx.aas.model.concept.ConceptDescription`. All objects only contain mandatory attributes. diff --git a/basyx/aas/examples/data/example_aas_missing_attributes.py b/basyx/aas/examples/data/example_aas_missing_attributes.py index e37f48acd..eac6cb440 100644 --- a/basyx/aas/examples/data/example_aas_missing_attributes.py +++ b/basyx/aas/examples/data/example_aas_missing_attributes.py @@ -5,8 +5,8 @@ # # SPDX-License-Identifier: MIT """ -Module for the creation of an :class:`ObjectStore ` with missing object attribute -combination for testing the serialization +Module for the creation of an :class:`ObjectStore ` with missing object +attribute combination for testing the serialization """ import datetime import logging @@ -19,9 +19,9 @@ def create_full_example() -> model.DictObjectStore: """ - Creates an :class:`~basyx.aas.model.provider.DictObjectStore` containing an example :class:`~basyx.aas.model.submodel.Submodel`, - an example :class:`~basyx.aas.model.concept.ConceptDescription` and an example - :class:`~basyx.aas.model.aas.AssetAdministrationShell` + Creates an :class:`~basyx.aas.model.provider.DictObjectStore` containing an example + :class:`~basyx.aas.model.submodel.Submodel`, an example :class:`~basyx.aas.model.concept.ConceptDescription` and an + example :class:`~basyx.aas.model.aas.AssetAdministrationShell` :return: :class:`basyx.aas.model.provider.DictObjectStore` """ diff --git a/basyx/aas/model/__init__.py b/basyx/aas/model/__init__.py index db91d8802..634e34c6c 100644 --- a/basyx/aas/model/__init__.py +++ b/basyx/aas/model/__init__.py @@ -22,8 +22,8 @@ :class:`~aas.model.concept.IEC61360ConceptDescription` provider.py - Providers for AAS objects, in order to store and retrieve :class:`~basyx.aas.model.base.Identifiable` objects by their - :class:`~basyx.aas.model.base.Identifier`. + Providers for AAS objects, in order to store and retrieve :class:`~basyx.aas.model.base.Identifiable` objects by + their :class:`~basyx.aas.model.base.Identifier`. submodel.py Meta-model of the submodels and events. diff --git a/basyx/aas/model/aas.py b/basyx/aas/model/aas.py index 8a6ffc70c..f9e31ff42 100644 --- a/basyx/aas/model/aas.py +++ b/basyx/aas/model/aas.py @@ -139,8 +139,8 @@ class AssetAdministrationShell(base.Identifiable, base.UniqueIdShortNamespace, b :ivar administration: :class:`~basyx.aas.model.base.AdministrativeInformation` of an :class:`~.basyx.aas.model.base.Identifiable` element. (inherited from :class:`~basyx.aas.model.base.Identifiable`) - :ivar ~.submodel: Unordered list of :class:`submodels ` to describe typically the asset - of an AAS. (Initialization-parameter: `submodel_`) + :ivar ~.submodel: Unordered list of :class:`submodels ` to describe typically + the asset of an AAS. (Initialization-parameter: `submodel_`) :ivar derived_from: The :class:`reference ` to the AAS the AAs was derived from :ivar embedded_data_specifications: List of Embedded data specification. :ivar extension: An extension of the element. diff --git a/basyx/aas/model/base.py b/basyx/aas/model/base.py index 59c0c11d9..01701b61f 100644 --- a/basyx/aas/model/base.py +++ b/basyx/aas/model/base.py @@ -72,8 +72,8 @@ class KeyTypes(Enum): :cvar ENTITY: :class:`~basyx.aas.model.submodel.Entity` :cvar EVENT_ELEMENT: :class:`~basyx.aas.model.submodel.EventElement`, Note: EventElement is abstract :cvar FILE: :class:`~basyx.aas.model.submodel.File` - :cvar MULTI_LANGUAGE_PROPERTY: :class:`~basyx.aas.model.submodel.MultiLanguageProperty` property with a value that can be - provided in multiple languages + :cvar MULTI_LANGUAGE_PROPERTY: :class:`~basyx.aas.model.submodel.MultiLanguageProperty` property with a value that + can be provided in multiple languages :cvar OPERATION: :class:`~basyx.aas.model.submodel.Operation` :cvar PROPERTY: :class:`~basyx.aas.model.submodel.Property` :cvar RANGE: :class:`~basyx.aas.model.submodel.Range` with min and max @@ -179,11 +179,11 @@ class EntityType(Enum): Enumeration for denoting whether an entity is a self-managed or a co-managed entity :cvar CO_MANAGED_ENTITY: For co-managed entities there is no separate - :class:`AAS `. Co-managed entities need to be part - of a self-managed entity + :class:`AAS `. Co-managed entities need to + be part of a self-managed entity :cvar SELF_MANAGED_ENTITY: Self-managed entities have their own - :class:`AAS `, but can be part of the bill of - material of a composite self-managed entity. + :class:`AAS `, but can be part of the bill + of material of a composite self-managed entity. """ CO_MANAGED_ENTITY = 0 @@ -836,8 +836,8 @@ def _direct_source_commit(self): class UnexpectedTypeError(TypeError): """ - Exception to be raised by :meth:`basyx.aas.model.base.ModelReference.resolve` if the retrieved object has not the expected - type. + Exception to be raised by :meth:`basyx.aas.model.base.ModelReference.resolve` if the retrieved object has not + the expected type. :ivar value: The object of unexpected type """ @@ -993,7 +993,8 @@ def resolve(self, provider_: "provider.AbstractObjectProvider") -> _RT: :param provider_: :class:`~basyx.aas.model.provider.AbstractObjectProvider` :return: The referenced object (or a proxy object for it) :raises IndexError: If the list of keys is empty - :raises TypeError: If one of the intermediate objects on the path is not a :class:`~basyx.aas.model.base.Namespace` + :raises TypeError: If one of the intermediate objects on the path is not a + :class:`~basyx.aas.model.base.Namespace` :raises UnexpectedTypeError: If the retrieved object is not of the expected type (or one of its subclasses). The object is stored in the `value` attribute of the exception :raises KeyError: If the reference could not be resolved @@ -1072,10 +1073,11 @@ def from_referable(referable: Referable) -> "ModelReference": :class:`~.Identifiable` object. Additionally, the object must be an instance of a known :class:`~.Referable` type. - :param referable: :class:`~basyx.aas.model.base.Referable` object to construct the :class:`~.ModelReference` from + :param referable: :class:`~basyx.aas.model.base.Referable` object to construct the :class:`~.ModelReference` + from :returns: Constructed :class:`~.ModelReference` - :raises ValueError: If no :class:`~basyx.aas.model.base.Identifiable` object is found while traversing the object's - ancestors + :raises ValueError: If no :class:`~basyx.aas.model.base.Identifiable` object is found while traversing the + object's ancestors """ # Get the first class from the base classes list (via inspect.getmro), that is contained in KEY_ELEMENTS_CLASSES from . import KEY_TYPES_CLASSES diff --git a/basyx/aas/model/concept.py b/basyx/aas/model/concept.py index 8f1a20730..d875667d7 100644 --- a/basyx/aas/model/concept.py +++ b/basyx/aas/model/concept.py @@ -39,8 +39,8 @@ class ConceptDescription(base.Identifiable, base.HasDataSpecification): :ivar ~.id: The globally unique id of the element. (inherited from :class:`~basyx.aas.model.base.Identifiable`) - :ivar is_case_of: Unordered list of global :class:`References ` to external definitions - the concept is compatible to or was derived from. + :ivar is_case_of: Unordered list of global :class:`References ` to external + definitions the concept is compatible to or was derived from. :ivar id_short: Identifying string of the element within its name space. (inherited from :class:`~basyx.aas.model.base.Referable`) :ivar display_name: Can be provided in several languages. (inherited from :class:`~basyx.aas.model.base.Referable`) diff --git a/basyx/aas/model/datatypes.py b/basyx/aas/model/datatypes.py index aac5b1a6d..2782bcc4b 100644 --- a/basyx/aas/model/datatypes.py +++ b/basyx/aas/model/datatypes.py @@ -16,11 +16,12 @@ There are three conversion functions for usage in BaSyx Python SDK's model and adapters: * :meth:`~aas.model.datatypes.xsd_repr` serializes any XSD type from this module into it's lexical representation -* :meth:`~basyx.aas.model.datatypes.from_xsd` parses an XSD type from its lexical representation (its required to name the - type for unambiguous conversion) -* :meth:`~basyx.aas.model.datatypes.trivial_cast` type-cast a python value into an XSD type, if this is trivially possible. - Meant for fixing the type of :class:`Properties' ` values automatically, esp. for literal - values. +* :meth:`~basyx.aas.model.datatypes.from_xsd` parses an XSD type from its lexical representation (its required to name + the type for unambiguous conversion) +* :meth:`~basyx.aas.model.datatypes.trivial_cast` type-cast a python value into an XSD type, + if this is trivially possible. + Meant for fixing the type of :class:`Properties' ` values automatically, + esp. for literal values. """ import base64 import datetime diff --git a/basyx/aas/model/provider.py b/basyx/aas/model/provider.py index 9415c61cc..1cc831281 100644 --- a/basyx/aas/model/provider.py +++ b/basyx/aas/model/provider.py @@ -6,8 +6,8 @@ # SPDX-License-Identifier: MIT """ This module implements Registries for the AAS, in order to enable resolving global -:class:`Identifiers `; and mapping :class:`Identifiers ` to -:class:`~basyx.aas.model.base.Identifiable` objects. +:class:`Identifiers `; and mapping +:class:`Identifiers ` to :class:`~basyx.aas.model.base.Identifiable` objects. """ import abc @@ -122,8 +122,8 @@ class ObjectProviderMultiplexer(AbstractObjectProvider): """ A multiplexer for Providers of :class:`~basyx.aas.model.base.Identifiable` objects. - This class combines multiple registries of :class:`~basyx.aas.model.base.Identifiable` objects into a single one to allow - retrieving :class:`~basyx.aas.model.base.Identifiable` objects from different sources. + This class combines multiple registries of :class:`~basyx.aas.model.base.Identifiable` objects into a single one + to allow retrieving :class:`~basyx.aas.model.base.Identifiable` objects from different sources. It implements the :class:`~.AbstractObjectProvider` interface to be used as registry itself. :ivar registries: A list of :class:`AbstractObjectProviders <.AbstractObjectProvider>` to query when looking up an diff --git a/basyx/aas/model/submodel.py b/basyx/aas/model/submodel.py index 656370735..2a674c37c 100644 --- a/basyx/aas/model/submodel.py +++ b/basyx/aas/model/submodel.py @@ -542,13 +542,15 @@ def __init__(self, class ReferenceElement(DataElement): """ - A reference element is a :class:`DataElement` that defines a :class:`~basyx.aas.model.base.Reference` to another element - within the same or another AAS or a :class:`~basyx.aas.model.base.Reference` to an external object or entity. + A reference element is a :class:`DataElement` that defines a :class:`~basyx.aas.model.base.Reference` to another + element within the same or another AAS or a :class:`~basyx.aas.model.base.Reference` to an external object + or entity. :ivar id_short: Identifying string of the element within its name space. (inherited from :class:`~basyx.aas.model.base.Referable`) - :ivar value: :class:`~basyx.aas.model.base.Reference` to any other :class:`~basyx.aas.model.base.Referable` element of the same - or any other AAS or a :class:`~basyx.aas.model.base.Reference` to an external object or entity. + :ivar value: :class:`~basyx.aas.model.base.Reference` to any other :class:`~basyx.aas.model.base.Referable` element + of the same or any other AAS or a :class:`~basyx.aas.model.base.Reference` to an external object + or entity. :ivar display_name: Can be provided in several languages. (inherited from :class:`~basyx.aas.model.base.Referable`) :ivar category: The category is a value that gives further meta information w.r.t. to the class of the element. It affects the expected existence of attributes and the applicability of constraints. @@ -822,7 +824,8 @@ def value_type_list_element(self) -> Optional[base.DataTypeDefXsd]: class RelationshipElement(SubmodelElement): """ - A relationship element is used to define a relationship between two :class:`~basyx.aas.model.base.Referable` elements. + A relationship element is used to define a relationship between two :class:`~basyx.aas.model.base.Referable` + elements. :ivar id_short: Identifying string of the element within its name space. (inherited from :class:`~basyx.aas.model.base.Referable`) @@ -937,9 +940,9 @@ class Operation(SubmodelElement, base.UniqueIdShortNamespace): In- and output variables are implemented as :class:`SubmodelElements <.SubmodelElement>` directly without the wrapping `OperationVariable`. This makes implementing *Constraint AASd-134* much easier since we can just use normal - :class:`NamespaceSets <~basyx.aas.model.base.NamespaceSet>`. Furthermore, an `OperationVariable` contains nothing besides - a single :class:`~.SubmodelElement` anyway, so implementing it would just make using `Operations` more tedious - for no reason. + :class:`NamespaceSets <~basyx.aas.model.base.NamespaceSet>`. Furthermore, an `OperationVariable` contains nothing + besides a single :class:`~.SubmodelElement` anyway, so implementing it would just make using `Operations` more + tedious for no reason. *Constraint AASd-134:* For an Operation, the idShort of all inputVariable/value, outputVariable/value, and inoutputVariable/value shall be unique. @@ -1055,8 +1058,8 @@ class Entity(SubmodelElement, base.UniqueIdShortNamespace): :ivar statement: Unordered list of statements (:class:`SubmodelElements <.SubmodelElement>`) applicable to the entity, typically with a qualified value. :ivar global_asset_id: Global :class:`~basyx.aas.model.base.Identifier` of the asset the entity is representing. - :ivar specific_asset_id: :class:`~basyx.aas.model.base.Reference` to an identifier key value pair representing a specific - identifier of the asset represented by the asset administration shell. + :ivar specific_asset_id: :class:`~basyx.aas.model.base.Reference` to an identifier key value pair representing a + specific identifier of the asset represented by the asset administration shell. See Constraint AASd-014 :ivar display_name: Can be provided in several languages. (inherited from :class:`~basyx.aas.model.base.Referable`) :ivar category: The category is a value that gives further meta information w.r.t. to the class of the element. @@ -1223,9 +1226,10 @@ class BasicEventElement(EventElement): :ivar id_short: Identifying string of the element within its name space. (inherited from :class:`~basyx.aas.model.base.Referable`) - :ivar observed: :class:`~basyx.aas.model.base.ModelReference` to the Referable, which defines the scope of the event. - Can be :class:`~basyx.aas.model.aas.AssetAdministrationShell`, :class:`~basyx.aas.model.submodel.SubmodelElement` - or :class:`~basyx.aas.model.submodel.SubmodelElement`. Reference to a referable, e.g. a data element + :ivar observed: :class:`~basyx.aas.model.base.ModelReference` to the Referable, which defines the scope of + the event. Can be :class:`~basyx.aas.model.aas.AssetAdministrationShell`, + :class:`~basyx.aas.model.submodel.SubmodelElement` or + :class:`~basyx.aas.model.submodel.SubmodelElement`. Reference to a referable, e.g. a data element or a submodel, that is being observed. :ivar direction: Direction of event as :class:`~basyx.aas.model.base.Direction`. :ivar state: State of event as :class:`~basyx.aas.model.base.StateOfEvent`. @@ -1234,8 +1238,9 @@ class BasicEventElement(EventElement): :ivar message_broker: Information, which outer message infrastructure shall handle messages for the EventElement. Refers to a :class:`~basyx.aas.model.submodel.SubmodelElement`, :class:`~basyx.aas.model.submodel.SubmodelElementList`, - :class:`~basyx.aas.model.submodel.SubmodelElementCollection` or :class:`~basyx.aas.model.submodel.Entity`, - which contains DataElements describing the proprietary specification for the message broker. + :class:`~basyx.aas.model.submodel.SubmodelElementCollection` or + :class:`~basyx.aas.model.submodel.Entity`, which contains DataElements describing the + proprietary specification for the message broker. Note: for different message infrastructure, e.g. OPC UA or MQTT or AMQP, this proprietary specification could be standardized by having respective Submodels. :ivar last_update: Timestamp in UTC, when the last event was received (input direction) or sent (output direction). diff --git a/basyx/aas/util/identification.py b/basyx/aas/util/identification.py index 858b0f4bf..50c2565e9 100644 --- a/basyx/aas/util/identification.py +++ b/basyx/aas/util/identification.py @@ -24,9 +24,8 @@ class AbstractIdentifierGenerator(metaclass=abc.ABCMeta): """ - Abstract base class for identifier generators that generate :class:`Identifiers ` based - on an internal schema and an - (optional) proposal. + Abstract base class for identifier generators that generate :class:`Identifiers ` + based on an internal schema and an (optional) proposal. Different Implementations of IdentifierGenerators may generate differently formed ids, e.g. URNs, HTTP-scheme IRIs, IRDIs, etc. Some of them may use a given private namespace and create ids within this namespace, others may just @@ -62,10 +61,9 @@ class NamespaceIRIGenerator(AbstractIdentifierGenerator): """ An IdentifierGenerator, that generates IRIs in a given namespace, checking uniqueness against a Registry. - :class:`Identifiers ` are generated by concatenating a fixed namespace with the proposed - suffix. To verify uniqueness, the - existence of the id is checked by querying the given Registry. If a collision - is detected, a number is prepended + :class:`Identifiers ` are generated by concatenating a fixed namespace + with the proposed suffix. To verify uniqueness, the existence of the id is checked by querying the given Registry. + If a collision is detected, a number is prepended :ivar namespace: The IRI Namespace to generate Identifiers in. It must be a valid IRI (starting with a scheme) and end on either #, /, or = to form a reasonable namespace. diff --git a/basyx/aas/util/traversal.py b/basyx/aas/util/traversal.py index 64c182261..97f1f568a 100644 --- a/basyx/aas/util/traversal.py +++ b/basyx/aas/util/traversal.py @@ -37,9 +37,9 @@ def walk_semantic_ids_recursive(root: model.Referable) -> Iterator[model.Referen :class:`SubmodelElements `) recursively and return all non-empty (!= None) semanticIds. - This is a generator function, yielding all the semanticIds. No :class:`~basyx.aas.model.base.Referable` objects should be - added, removed or moved to/from/in the AAS object hierarchy while iterating, as this could result in undefined - behaviour. + This is a generator function, yielding all the semanticIds. No :class:`~basyx.aas.model.base.Referable` objects + should be added, removed or moved to/from/in the AAS object hierarchy while iterating, as this could result + in undefined behaviour. """ if isinstance(root, model.HasSemantics): if root.semantic_id is not None: