Skip to content

Commit

Permalink
fix pycodestyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhsjdhjs committed Dec 22, 2023
1 parent 4567870 commit b440745
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 118 deletions.
63 changes: 31 additions & 32 deletions basyx/aas/adapter/aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <basyx.aas.model.submodel.Submodel>` 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 <basyx.aas.model.submodel.Submodel>`
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 <aas.model.provider.AbstractObjectStore>` 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 <basyx.aas.model.base.Identifier>` of all
:class:`~basyx.aas.model.base.Identifiable` objects parsed from the AASX file
"""
Expand Down Expand Up @@ -323,19 +322,18 @@ def write_aas(self,
write_json: bool = False) -> None:
"""
Convenience method to write one or more
:class:`AssetAdministrationShells <basyx.aas.model.aas.AssetAdministrationShell>` 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 <basyx.aas.model.base.Identifier>` (as `aas_ids`) to retrieve the
AASs from the given object_store.
:class:`References <basyx.aas.model.base.Reference>` to :class:`Submodels <basyx.aas.model.submodel.Submodel>` and
:class:`ConceptDescriptions <basyx.aas.model.concept.ConceptDescription>` (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 <basyx.aas.model.submodel.Submodel>` are also added to the AASX
package.
:class:`AssetAdministrationShells <basyx.aas.model.aas.AssetAdministrationShell>` 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 <basyx.aas.model.base.Identifier>` (as `aas_ids`) to retrieve
the AASs from the given object_store.
:class:`References <basyx.aas.model.base.Reference>` to :class:`Submodels <basyx.aas.model.submodel.Submodel>`
and :class:`ConceptDescriptions <basyx.aas.model.concept.ConceptDescription>` (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 <basyx.aas.model.submodel.Submodel>` are also added to the AASX package.
This method uses `write_all_aas_objects()` to write the AASX part.
Expand All @@ -351,16 +349,18 @@ def write_aas(self,
:param aas_ids: :class:`~basyx.aas.model.base.Identifier` or Iterable of
:class:`Identifiers <basyx.aas.model.base.Identifier>` of the AAS(s) to be written to the AASX file
:param object_store: :class:`ObjectStore <aas.model.provider.AbstractObjectStore>` 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 <basyx.aas.model.submodel.Submodel>` and
:class:`ConceptDescriptions <basyx.aas.model.concept.ConceptDescription>` are skipped, logging a warning/info
message)
:class:`ConceptDescriptions <basyx.aas.model.concept.ConceptDescription>` 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)
"""
Expand Down Expand Up @@ -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::
Expand All @@ -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 <basyx.aas.model.base.Identifier>` 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 <basyx.aas.model.base.Identifier>` 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 <aas.adapter.aasx.AbstractSupplementaryFileContainer>`
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <tutorial_backend_couchdb>`
"""
24 changes: 12 additions & 12 deletions basyx/aas/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions basyx/aas/backend/couchdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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
"""
Expand Down
11 changes: 6 additions & 5 deletions basyx/aas/backend/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/examples/data/example_aas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/examples/data/example_aas_mandatory_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# SPDX-License-Identifier: MIT
"""
Module for the creation of an :class:`ObjectStore <basyx.aas.model.provider.DictObjectStore>` with an example
:class:`~basyx.aas.model.aas.AssetAdministrationShell` and example :class:`Submodels <basyx.aas.model.submodel.Submodel>`
and a :class:`~aas.model.concept.ConceptDictionary` containing an
:class:`~basyx.aas.model.aas.AssetAdministrationShell` and example
:class:`Submodels <basyx.aas.model.submodel.Submodel>` and a :class:`~aas.model.concept.ConceptDictionary` containing an
example :class:`~basyx.aas.model.concept.ConceptDescription`. All objects only contain mandatory
attributes.
Expand Down
10 changes: 5 additions & 5 deletions basyx/aas/examples/data/example_aas_missing_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#
# SPDX-License-Identifier: MIT
"""
Module for the creation of an :class:`ObjectStore <basyx.aas.model.provider.DictObjectStore>` with missing object attribute
combination for testing the serialization
Module for the creation of an :class:`ObjectStore <basyx.aas.model.provider.DictObjectStore>` with missing object
attribute combination for testing the serialization
"""
import datetime
import logging
Expand All @@ -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`
"""
Expand Down
Loading

0 comments on commit b440745

Please sign in to comment.