You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2022/04/10 19:36:39 UTC

[plc4x] branch develop updated (f968b7c9b3 -> ee8baef10a)

This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


    from f968b7c9b3 Feature/plc4py bh1 (#341)
     new 9181ef948d chore(plc4py): update pre-commit repos
     new ee8baef10a Fix pre-commit errors

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sandbox/plc4py/.pre-commit-config.yaml                   |  9 +++++----
 sandbox/plc4py/plc4py/PlcDriverManager.py                | 16 ++++++++++------
 sandbox/plc4py/plc4py/api/PlcConnection.py               |  6 ++----
 sandbox/plc4py/plc4py/api/__init__.py                    |  2 +-
 sandbox/plc4py/plc4py/api/exceptions/__init__.py         |  2 +-
 sandbox/plc4py/plc4py/api/exceptions/exceptions.py       |  4 ++--
 sandbox/plc4py/plc4py/api/messages/PlcMessage.py         |  3 ++-
 sandbox/plc4py/plc4py/api/messages/PlcRequest.py         |  1 -
 sandbox/plc4py/plc4py/api/messages/PlcResponse.py        |  3 +--
 sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py     |  2 +-
 sandbox/plc4py/plc4py/drivers/__init__.py                |  2 +-
 sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py |  7 +++----
 sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py        |  1 -
 sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py  |  2 +-
 sandbox/plc4py/plc4py/utils/GenericTypes.py              |  6 +++---
 sandbox/plc4py/tests/test_plc4py.py                      |  2 ++
 sandbox/plc4py/tests/unit/__init__.py                    |  2 +-
 sandbox/plc4py/tests/unit/plc4py/__init__.py             |  2 +-
 .../tests/unit/plc4py/api/test/MockPlcConection.py       |  2 --
 .../tests/unit/plc4py/api/test/MockReadRequestBuilder.py | 10 ++++++++--
 .../plc4py/tests/unit/plc4py/test_PlcDriverManager.py    |  6 +-----
 21 files changed, 46 insertions(+), 44 deletions(-)


[plc4x] 02/02: Fix pre-commit errors

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit ee8baef10a3707ed1c133355ac339ad28c85a6cf
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Mon Apr 11 05:35:52 2022 +1000

    Fix pre-commit errors
---
 sandbox/plc4py/.pre-commit-config.yaml                   |  1 +
 sandbox/plc4py/plc4py/PlcDriverManager.py                | 16 ++++++++++------
 sandbox/plc4py/plc4py/api/PlcConnection.py               |  6 ++----
 sandbox/plc4py/plc4py/api/__init__.py                    |  2 +-
 sandbox/plc4py/plc4py/api/exceptions/__init__.py         |  2 +-
 sandbox/plc4py/plc4py/api/exceptions/exceptions.py       |  4 ++--
 sandbox/plc4py/plc4py/api/messages/PlcMessage.py         |  3 ++-
 sandbox/plc4py/plc4py/api/messages/PlcRequest.py         |  1 -
 sandbox/plc4py/plc4py/api/messages/PlcResponse.py        |  3 +--
 sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py     |  2 +-
 sandbox/plc4py/plc4py/drivers/__init__.py                |  2 +-
 sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py |  7 +++----
 sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py        |  1 -
 sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py  |  2 +-
 sandbox/plc4py/plc4py/utils/GenericTypes.py              |  6 +++---
 sandbox/plc4py/tests/test_plc4py.py                      |  2 ++
 sandbox/plc4py/tests/unit/__init__.py                    |  2 +-
 sandbox/plc4py/tests/unit/plc4py/__init__.py             |  2 +-
 .../tests/unit/plc4py/api/test/MockPlcConection.py       |  2 --
 .../tests/unit/plc4py/api/test/MockReadRequestBuilder.py | 10 ++++++++--
 .../plc4py/tests/unit/plc4py/test_PlcDriverManager.py    |  6 +-----
 21 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/sandbox/plc4py/.pre-commit-config.yaml b/sandbox/plc4py/.pre-commit-config.yaml
index abfdaa99a1..4a04526263 100644
--- a/sandbox/plc4py/.pre-commit-config.yaml
+++ b/sandbox/plc4py/.pre-commit-config.yaml
@@ -38,6 +38,7 @@ repos:
     rev: 3.9.2
     hooks:
     -   id: flake8
+        args: ['--max-line-length','120']
         types: [python]
 -   repo: https://github.com/psf/black
     rev: 22.3.0 # Replace by any tag/version: https://github.com/psf/black/tags
diff --git a/sandbox/plc4py/plc4py/PlcDriverManager.py b/sandbox/plc4py/plc4py/PlcDriverManager.py
index 5f7cbbafbe..8f67acb7df 100644
--- a/sandbox/plc4py/plc4py/PlcDriverManager.py
+++ b/sandbox/plc4py/plc4py/PlcDriverManager.py
@@ -18,7 +18,6 @@
 #
 
 import logging
-import sys
 from contextlib import contextmanager
 from dataclasses import dataclass, field
 from typing import Generator, Type
@@ -35,20 +34,26 @@ class PlcDriverManager:
     _driverMap: dict[str, Type[PlcConnection]] = field(default_factory=lambda: {})
 
     def __post_init__(self):
-        logging.info(f"Instantiating new PLC Driver Manager with class loader {self.class_loader}")
+        logging.info(
+            f"Instantiating new PLC Driver Manager with class loader {self.class_loader}"
+        )
         self.class_loader.add_hookspecs(PlcDriverClassLoader)
         logging.info("Registering available drivers...")
 
         import plc4py.drivers
+
         self.class_loader.register(plc4py.drivers)
         self.class_loader.load_setuptools_entrypoints("plc4py.drivers")
-        self._driverMap = {key: loader for key, loader in zip(self.class_loader.hook.key(),
-                                                              self.class_loader.hook.get_connection())}
+        self._driverMap = {
+            key: loader
+            for key, loader in zip(
+                self.class_loader.hook.key(), self.class_loader.hook.get_connection()
+            )
+        }
         for driver in self._driverMap:
             logging.info(f"... {driver} .. OK")
         self.class_loader.check_pending()
 
-
     @contextmanager
     def connection(self, url: str) -> Generator[PlcConnection, None, None]:
         """
@@ -97,4 +102,3 @@ class PlcDriverManager:
         """
         protocol_code = get_protocol_code(url)
         return self._driverMap[protocol_code]
-
diff --git a/sandbox/plc4py/plc4py/api/PlcConnection.py b/sandbox/plc4py/plc4py/api/PlcConnection.py
index 4889ed898c..ebb9773ef9 100644
--- a/sandbox/plc4py/plc4py/api/PlcConnection.py
+++ b/sandbox/plc4py/plc4py/api/PlcConnection.py
@@ -17,17 +17,15 @@
 # under the License.
 #
 from abc import abstractmethod
-from dataclasses import dataclass
-
 
 from plc4py.api.messages.PlcRequest import ReadRequestBuilder
 from plc4py.api.exceptions.exceptions import PlcConnectionException
 from plc4py.utils.GenericTypes import GenericGenerator
 
 
-@dataclass
 class PlcConnection(GenericGenerator):
-    url: str = ""
+    def __init__(self, url: str):
+        self.url = url
 
     @abstractmethod
     def connect(self) -> None:
diff --git a/sandbox/plc4py/plc4py/api/__init__.py b/sandbox/plc4py/plc4py/api/__init__.py
index 797783f2b3..585be9602f 100644
--- a/sandbox/plc4py/plc4py/api/__init__.py
+++ b/sandbox/plc4py/plc4py/api/__init__.py
@@ -15,4 +15,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
\ No newline at end of file
+#
diff --git a/sandbox/plc4py/plc4py/api/exceptions/__init__.py b/sandbox/plc4py/plc4py/api/exceptions/__init__.py
index 797783f2b3..585be9602f 100644
--- a/sandbox/plc4py/plc4py/api/exceptions/__init__.py
+++ b/sandbox/plc4py/plc4py/api/exceptions/__init__.py
@@ -15,4 +15,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
\ No newline at end of file
+#
diff --git a/sandbox/plc4py/plc4py/api/exceptions/exceptions.py b/sandbox/plc4py/plc4py/api/exceptions/exceptions.py
index d62c6345f4..a28140fdbc 100644
--- a/sandbox/plc4py/plc4py/api/exceptions/exceptions.py
+++ b/sandbox/plc4py/plc4py/api/exceptions/exceptions.py
@@ -18,8 +18,8 @@ import logging
 
 
 class PlcException(Exception):
-    pass;
+    pass
 
 
 class PlcConnectionException(Exception):
-    logging.error(f"Unable to establish a connection to the plc")
+    logging.error("Unable to establish a connection to the plc")
diff --git a/sandbox/plc4py/plc4py/api/messages/PlcMessage.py b/sandbox/plc4py/plc4py/api/messages/PlcMessage.py
index 3e1d48e9a5..a278f40061 100644
--- a/sandbox/plc4py/plc4py/api/messages/PlcMessage.py
+++ b/sandbox/plc4py/plc4py/api/messages/PlcMessage.py
@@ -17,5 +17,6 @@
 # under the License.
 #
 
+
 class PlcMessage:
-    pass
\ No newline at end of file
+    pass
diff --git a/sandbox/plc4py/plc4py/api/messages/PlcRequest.py b/sandbox/plc4py/plc4py/api/messages/PlcRequest.py
index 2684814329..8f5084ced7 100644
--- a/sandbox/plc4py/plc4py/api/messages/PlcRequest.py
+++ b/sandbox/plc4py/plc4py/api/messages/PlcRequest.py
@@ -38,7 +38,6 @@ class PlcField:
 
 
 class ReadRequestBuilder(GenericGenerator):
-
     @abstractmethod
     def build(self) -> PlcRequest:
         pass
diff --git a/sandbox/plc4py/plc4py/api/messages/PlcResponse.py b/sandbox/plc4py/plc4py/api/messages/PlcResponse.py
index 35ec0ec425..6e55b2fc5c 100644
--- a/sandbox/plc4py/plc4py/api/messages/PlcResponse.py
+++ b/sandbox/plc4py/plc4py/api/messages/PlcResponse.py
@@ -18,7 +18,6 @@ from plc4py.api.messages.PlcRequest import PlcMessage
 
 
 class PlcResponse(PlcMessage):
-
     @abstractmethod
     def get_request(self) -> PlcMessage:
-        pass
\ No newline at end of file
+        pass
diff --git a/sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py b/sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py
index 2cd0d13983..cc8b757ad7 100644
--- a/sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py
+++ b/sandbox/plc4py/plc4py/drivers/PlcConnectionLoader.py
@@ -42,4 +42,4 @@ class PlcConnectionLoader:
         """
         :return str: Unique key to identify the driver
         """
-        pass
\ No newline at end of file
+        pass
diff --git a/sandbox/plc4py/plc4py/drivers/__init__.py b/sandbox/plc4py/plc4py/drivers/__init__.py
index 8f1f9a87b1..b74423fa90 100644
--- a/sandbox/plc4py/plc4py/drivers/__init__.py
+++ b/sandbox/plc4py/plc4py/drivers/__init__.py
@@ -13,4 +13,4 @@
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
-# under the License.
\ No newline at end of file
+# under the License.
diff --git a/sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py b/sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py
index 0a3906eb7e..5a8dd73277 100644
--- a/sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py
+++ b/sandbox/plc4py/plc4py/drivers/modbus/ModbusConnection.py
@@ -16,7 +16,6 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-from dataclasses import dataclass
 from typing import Type
 
 import plc4py
@@ -25,10 +24,12 @@ from plc4py.api.messages.PlcRequest import ReadRequestBuilder
 from plc4py.drivers.PlcConnectionLoader import PlcConnectionLoader
 
 
-@dataclass
 class ModbusConnection(PlcConnection):
     """A hook implementation namespace."""
 
+    def __init__(self, url: str):
+        super().__init__(url)
+
     def connect(self):
         """
         Establishes the connection to the remote PLC.
@@ -57,7 +58,6 @@ class ModbusConnection(PlcConnection):
 
 
 class ModbusConnectionLoader(PlcConnectionLoader):
-
     @staticmethod
     @plc4py.hookimpl
     def get_connection() -> Type[ModbusConnection]:
@@ -67,4 +67,3 @@ class ModbusConnectionLoader(PlcConnectionLoader):
     @plc4py.hookimpl
     def key() -> str:
         return "modbus"
-
diff --git a/sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py b/sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py
index 97fd65e410..876dbae630 100644
--- a/sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py
+++ b/sandbox/plc4py/plc4py/spi/PlcDriverClassLoader.py
@@ -22,7 +22,6 @@ import pluggy
 from plc4py.api.PlcConnection import PlcConnection
 
 
-
 class PlcDriverClassLoader:
     """Hook spec for PLC4PY Driver Loaders"""
 
diff --git a/sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py b/sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py
index 4dcdb4f0a7..8e03b35bf2 100644
--- a/sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py
+++ b/sandbox/plc4py/plc4py/utils/ConnectionStringHandling.py
@@ -19,6 +19,7 @@
 
 from urllib.parse import urlparse
 
+
 def get_protocol_code(url: str) -> str:
     """
     Get the protocol code section of the connection string
@@ -29,4 +30,3 @@ def get_protocol_code(url: str) -> str:
     """
     parsed = urlparse(url)
     return parsed.scheme
-
diff --git a/sandbox/plc4py/plc4py/utils/GenericTypes.py b/sandbox/plc4py/plc4py/utils/GenericTypes.py
index 36acd646be..208d00d4d3 100644
--- a/sandbox/plc4py/plc4py/utils/GenericTypes.py
+++ b/sandbox/plc4py/plc4py/utils/GenericTypes.py
@@ -19,9 +19,9 @@
 
 from typing import Generator
 
-#TODO: Figure out what the parameters are and if we need this
-class GenericGenerator(Generator):
 
+# TODO: Figure out what the parameters are and if we need this
+class GenericGenerator(Generator):
     def __enter__(self):
         return self
 
@@ -32,4 +32,4 @@ class GenericGenerator(Generator):
         pass
 
     def __exit__(self, *args):
-        pass
\ No newline at end of file
+        pass
diff --git a/sandbox/plc4py/tests/test_plc4py.py b/sandbox/plc4py/tests/test_plc4py.py
index 670e4dfffc..5427c832b5 100644
--- a/sandbox/plc4py/tests/test_plc4py.py
+++ b/sandbox/plc4py/tests/test_plc4py.py
@@ -26,11 +26,13 @@ from plc4py.drivers.modbus.ModbusConnection import ModbusConnection
 def test_version():
     assert __version__ == "0.1.0"
 
+
 def test_plc_driver_manager_init():
     driver_manager = PlcDriverManager()
     with driver_manager.connection("modbus:tcp://127.0.0.1:502") as connection:
         assert isinstance(connection, PlcConnection)
 
+
 def test_plc_driver_manager_init_modbus():
     driver_manager = PlcDriverManager()
     with driver_manager.connection("modbus:tcp://127.0.0.1:502") as connection:
diff --git a/sandbox/plc4py/tests/unit/__init__.py b/sandbox/plc4py/tests/unit/__init__.py
index 797783f2b3..585be9602f 100644
--- a/sandbox/plc4py/tests/unit/__init__.py
+++ b/sandbox/plc4py/tests/unit/__init__.py
@@ -15,4 +15,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
\ No newline at end of file
+#
diff --git a/sandbox/plc4py/tests/unit/plc4py/__init__.py b/sandbox/plc4py/tests/unit/plc4py/__init__.py
index 797783f2b3..585be9602f 100644
--- a/sandbox/plc4py/tests/unit/plc4py/__init__.py
+++ b/sandbox/plc4py/tests/unit/plc4py/__init__.py
@@ -15,4 +15,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
\ No newline at end of file
+#
diff --git a/sandbox/plc4py/tests/unit/plc4py/api/test/MockPlcConection.py b/sandbox/plc4py/tests/unit/plc4py/api/test/MockPlcConection.py
index 0dcdff5de8..7cb55f8992 100644
--- a/sandbox/plc4py/tests/unit/plc4py/api/test/MockPlcConection.py
+++ b/sandbox/plc4py/tests/unit/plc4py/api/test/MockPlcConection.py
@@ -53,5 +53,3 @@ class MockPlcConnection(PlcConnection):
         :return: read request builder.
         """
         return MockReadRequestBuilder()
-
-
diff --git a/sandbox/plc4py/tests/unit/plc4py/api/test/MockReadRequestBuilder.py b/sandbox/plc4py/tests/unit/plc4py/api/test/MockReadRequestBuilder.py
index 4ead140ef3..ed2c8d7cd6 100644
--- a/sandbox/plc4py/tests/unit/plc4py/api/test/MockReadRequestBuilder.py
+++ b/sandbox/plc4py/tests/unit/plc4py/api/test/MockReadRequestBuilder.py
@@ -16,8 +16,14 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-from plc4py.api.messages.PlcRequest import ReadRequestBuilder
+from typing import Union
+
+from plc4py.api.messages.PlcRequest import ReadRequestBuilder, PlcRequest, PlcField
 
 
 class MockReadRequestBuilder(ReadRequestBuilder):
-    pass
\ No newline at end of file
+    def build(self) -> PlcRequest:
+        pass
+
+    def add_item(self, field_query: Union[str, PlcField]) -> PlcRequest:
+        pass
diff --git a/sandbox/plc4py/tests/unit/plc4py/test_PlcDriverManager.py b/sandbox/plc4py/tests/unit/plc4py/test_PlcDriverManager.py
index ba79e9e3cf..a18b652f64 100644
--- a/sandbox/plc4py/tests/unit/plc4py/test_PlcDriverManager.py
+++ b/sandbox/plc4py/tests/unit/plc4py/test_PlcDriverManager.py
@@ -16,11 +16,9 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-from typing import Union
 from unittest.mock import MagicMock
 
 from plc4py.PlcDriverManager import PlcDriverManager
-from plc4py.api.PlcConnection import PlcConnection
 from tests.unit.plc4py.api.test.MockPlcConection import MockPlcConnection
 
 
@@ -31,12 +29,10 @@ def test_connection_context_manager_impl_close_called(mocker) -> None:
     connection_mock: MagicMock = mocker.patch.object(manager, "get_connection")
     connection_mock.return_value = MockPlcConnection()
 
-    close_mock: Union[MagicMock, None] = None
-
     # the connection function is supposed to support context manager
     # so using it in a with statement should result in close being called on the connection
     with manager.connection("foo://bar") as conn:
-        close_mock = mocker.patch.object(conn, "close")
+        close_mock: MagicMock = mocker.patch.object(conn, "close")
         print(conn.__doc__)
 
     # verify that close was called by the context manager


[plc4x] 01/02: chore(plc4py): update pre-commit repos

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 9181ef948daa781bbcb92a4091f5b4983aff773f
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Mon Apr 11 05:08:51 2022 +1000

    chore(plc4py): update pre-commit repos
---
 sandbox/plc4py/.pre-commit-config.yaml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sandbox/plc4py/.pre-commit-config.yaml b/sandbox/plc4py/.pre-commit-config.yaml
index e3ce9274e8..abfdaa99a1 100644
--- a/sandbox/plc4py/.pre-commit-config.yaml
+++ b/sandbox/plc4py/.pre-commit-config.yaml
@@ -28,25 +28,25 @@
 # should configure this at the top level
 repos:
 -   repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v2.4.0
+    rev: v4.2.0
     hooks:
     -   id: trailing-whitespace
         types: [python]
     -   id: end-of-file-fixer
         types: [python]
 -   repo: https://gitlab.com/pycqa/flake8
-    rev: 3.8.3
+    rev: 3.9.2
     hooks:
     -   id: flake8
         types: [python]
 -   repo: https://github.com/psf/black
-    rev: 19.10b0 # Replace by any tag/version: https://github.com/psf/black/tags
+    rev: 22.3.0 # Replace by any tag/version: https://github.com/psf/black/tags
     hooks:
       - id: black
         language_version: python3 # Should be a command that runs python3.6
         types: [python]
 -   repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v0.782
+    rev: v0.942
     hooks:
     -   id: mypy
         types: [python]
\ No newline at end of file