From 73175b9c5938d780352c1a2cbcf7a888825535fe Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Tue, 15 Oct 2024 13:43:25 +0200 Subject: [PATCH] Add pre-commit-config --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/dependabot.yml | 2 +- .github/workflows/python-package.yml | 25 +++++++++++++------ .pre-commit-config.yaml | 22 ++++++++++++++++ .readthedocs.yml | 2 +- CHANGELOG.md | 24 +++++++++--------- README.md | 12 +++++++++ asyncua/common/xmlimporter.py | 2 +- asyncua/ua/uaerrors/_auto.py | 2 -- asyncua/ua/uaprotocol_auto.py | 2 +- docs/api/asyncua.client.ha.rst | 1 - docs/api/asyncua.client.rst | 1 - docs/api/asyncua.common.rst | 1 - docs/api/asyncua.crypto.rst | 1 - docs/api/asyncua.server.rst | 1 - .../asyncua.server.standard_address_space.rst | 1 - docs/api/asyncua.ua.uaerrors.rst | 1 - docs/api/index.rst | 2 +- docs/index.rst | 2 +- docs/requirements.txt | 2 +- docs/usage/client/overview.rst | 2 -- docs/usage/common/node-nodeid.rst | 20 +++++++-------- docs/usage/common/overview.rst | 2 -- docs/usage/get-started/installation.rst | 8 +++--- docs/usage/get-started/minimal-client.rst | 4 +-- docs/usage/get-started/minimal-server.rst | 10 ++++---- docs/usage/get-started/opc-ua-basics.rst | 7 +++--- docs/usage/index.rst | 8 +++--- docs/usage/server/overview.rst | 2 +- docs/usage/sync/overview.rst | 2 +- schemas/README.md | 11 ++++---- schemas/generate_model_event.py | 4 +-- schemas/generate_protocol_python.py | 2 +- .../custom_extension_with_optional_fields.xml | 2 +- tests/custom_nodes.xml | 20 +++++++-------- tests/custom_nodesns.xml | 4 +-- tests/custom_nodesns_2.xml | 4 +-- tests/custom_nodesns_3.xml | 2 +- tests/custom_nodesns_4.xml | 6 ++--- tests/example.bsd | 2 +- tools/uaserver | 2 +- 41 files changed, 131 insertions(+), 101 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 112e8458b..86475f55d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,7 +9,7 @@ assignees: '' ### Please read, before you post! -This is a _**BUG REPORT for issues in the existing code**_. +This is a _**BUG REPORT for issues in the existing code**_. If you have general questions, code handling problems or ideas, please use the: diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0ce3e131b..a81eb7c93 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,4 +8,4 @@ updates: directory: "/" schedule: # Check for updates to GitHub Actions every week - interval: "weekly" \ No newline at end of file + interval: "weekly" diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ee96ccf47..15d5086da 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -32,13 +32,24 @@ jobs: python -m pip install pytest mypy ruff if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if [ -f dev_requirements.txt ]; then pip install -r dev_requirements.txt; fi - - name: Lint with ruff - run: | - ruff check . - - name: mypy - run: | - python -m pip install types-aiofiles types-python-dateutil types-pytz typing-extensions - python -m mypy asyncua/ - name: Test with pytest run: | pytest -v -s + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install pre-commit + - name: Lint with ruff + run: | + pre-commit run -a diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e2ccaf786 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + args: [--unsafe] + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.6.9' + hooks: + - id: ruff + args: ['--fix'] + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.12.0 + hooks: + - id: mypy + additional_dependencies: [types-aiofiles, types-python-dateutil, types-pytz, typing-extensions, aiosqlite, types-pyOpenSSL] + files: ^asyncua/.* diff --git a/.readthedocs.yml b/.readthedocs.yml index f55d1ba88..43515456d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -21,4 +21,4 @@ python: install: - requirements: docs/requirements.txt - method: pip - path: . \ No newline at end of file + path: . diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e00e4956..41f54148c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#1277](https://github.com/FreeOpcUa/opcua-asyncio/pull/1277) - Fixed incorrect function signature in Node and it's Sync wrapper [#1690](https://github.com/FreeOpcUa/opcua-asyncio/pull/1690) - + ## [1.0.2] - 2022-04-05 ### Added @@ -68,16 +68,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes -- Fix publishing in high load situations +- Fix publishing in high load situations [#1265](https://github.com/FreeOpcUa/opcua-asyncio/pull/1265) - Fix MonitoredItemServer._is_data_changed, when as trigger ua.DataChangeTrigger.StatusValueTimestamp is used [#1253](https://github.com/FreeOpcUa/opcua-asyncio/pull/1253) - fix monitoritem for mutable values [#1243](https://github.com/FreeOpcUa/opcua-asyncio/pull/1243) -- Respect EndpointUrl request parameter in GetEndpoints, FindServers and CreateSession +- Respect EndpointUrl request parameter in GetEndpoints, FindServers and CreateSession [#1232](https://github.com/FreeOpcUa/opcua-asyncio/pull/1232) -- fix server history save event; init list before use +- fix server history save event; init list before use [#1222](https://github.com/FreeOpcUa/opcua-asyncio/pull/1222) - xmlexporter: fix extensionobjects typeid indentifier missing namespace mapping to idx_in_exported_file [#1201](https://github.com/FreeOpcUa/opcua-asyncio/pull/1201) @@ -129,7 +129,7 @@ in `__enter__` in sync wrapper ### Added - add feat: subscription.py optional param for sampling_interval [#1087](https://github.com/FreeOpcUa/opcua-asyncio/pull/1087) - + ### Changed @@ -154,7 +154,7 @@ in `__enter__` in sync wrapper - Fix typo in in XmlImporte._check_if_namespace_meta_information_is_add ed which results in an exception [#1066](https://github.com/FreeOpcUa/opcua-asyncio/pull/1066) - + ## [0.9.98] - 2022-09-27 @@ -165,7 +165,7 @@ results in an exception - enhance nodeset generator: add Windows support and allow targeting a branch [#1049](https://github.com/FreeOpcUa/opcua-asyncio/pull/1049) -### Changed +### Changed - review all big exception handlings and try to better follow best practices [#1048](https://github.com/FreeOpcUa/opcua-asyncio/pull/1048) - update schema to v1.05.01 2022-02-24 @@ -209,7 +209,7 @@ results in an exception [#1005](https://github.com/FreeOpcUa/opcua-asyncio/pull/1005) - Properly close session if `connect` fails in `activate_session` [#1001](https://github.com/FreeOpcUa/opcua-asyncio/pull/1001) -- xmlimport change datatype field default +- xmlimport change datatype field default [#1008](https://github.com/FreeOpcUa/opcua-asyncio/pull/1008) - fixed an UnboundLocalError [#1012](https://github.com/FreeOpcUa/opcua-asyncio/pull/1012) @@ -237,7 +237,7 @@ results in an exception - Completion of the Sync api: add some missing methods [#975](https://github.com/FreeOpcUa/opcua-asyncio/pull/975) -### Changed +### Changed - Rework struct1_04 resolution [#901](https://github.com/FreeOpcUa/opcua-asyncio/pull/901) - Handle objects in EventTypes. If a EventType has a object as child, add it's @@ -260,7 +260,7 @@ import continues. [#911](https://github.com/FreeOpcUa/opcua-asyncio/pull/911) - Fix _open_secure_channel_exchange typehints [#920](https://github.com/FreeOpcUa/opcua-asyncio/pull/920) -- Fix: Value in DataValue can be optional +- Fix: Value in DataValue can be optional [#931](https://github.com/FreeOpcUa/opcua-asyncio/pull/931) - You can now call `activate_session()` without arguments without discarding a certificate previously set with `load_client_certificate()`. @@ -294,7 +294,7 @@ _node_to_string correctly maps namespaces idxs - Fix default value for structs with lists [#894](https://github.com/FreeOpcUa/opcua-asyncio/pull/894) -- Fix enum regression +- Fix enum regression [#898](https://github.com/FreeOpcUa/opcua-asyncio/pull/898) -- Set Client locale +- Set Client locale [#890](https://github.com/FreeOpcUa/opcua-asyncio/pull/890) diff --git a/README.md b/README.md index b4d05a794..4a8c57b75 100644 --- a/README.md +++ b/README.md @@ -210,3 +210,15 @@ Or ``` ./run-test.sh -v -s --cov asyncua --cov-report=html ``` + +## Linting + +To apply linting checks (including ruff, and mypy) at each commit run, +```bash +pip install pre-commit +pre-commit install +``` +You can also run all linters on all files with, +```bash +pre-commit run -a +``` \ No newline at end of file diff --git a/asyncua/common/xmlimporter.py b/asyncua/common/xmlimporter.py index d267e1bce..df6b9991e 100644 --- a/asyncua/common/xmlimporter.py +++ b/asyncua/common/xmlimporter.py @@ -482,7 +482,7 @@ def _set_attr(self, atttype, fargs, attname: str, val): self._set_attr(sub_atttype, subargs, attname2, v2) if "Encoding" in subargs: del subargs["Encoding"] - fargs[attname] = atttype(**subargs) + fargs[attname] = atttype(**subargs) # type: ignore[operator] else: raise RuntimeError(f"Could not handle type {atttype} of type {type(atttype)}") diff --git a/asyncua/ua/uaerrors/_auto.py b/asyncua/ua/uaerrors/_auto.py index edf5574e2..c207dea65 100644 --- a/asyncua/ua/uaerrors/_auto.py +++ b/asyncua/ua/uaerrors/_auto.py @@ -857,5 +857,3 @@ class BadMaxConnectionsReached(UaStatusCodeError): class BadDataSetIdInvalid(UaStatusCodeError): code = 0x80E70000 - - diff --git a/asyncua/ua/uaprotocol_auto.py b/asyncua/ua/uaprotocol_auto.py index 02d31b3b5..0a433a09a 100644 --- a/asyncua/ua/uaprotocol_auto.py +++ b/asyncua/ua/uaprotocol_auto.py @@ -11,7 +11,7 @@ from asyncua.ua.uatypes import FROZEN from asyncua.ua.uatypes import SByte, Byte, Bytes, ByteString, Int16, Int32, Int64, UInt16, UInt32 from asyncua.ua.uatypes import UInt64, Boolean, Float, Double, Null, String, CharArray, DateTime, Guid -from asyncua.ua.uatypes import AccessLevel, EventNotifier +from asyncua.ua.uatypes import AccessLevel, EventNotifier from asyncua.ua.uatypes import LocalizedText, Variant, QualifiedName, StatusCode, DataValue from asyncua.ua.uatypes import RelativePath, RelativePathElement from asyncua.ua.uatypes import NodeId, FourByteNodeId, ExpandedNodeId, ExtensionObject, DiagnosticInfo diff --git a/docs/api/asyncua.client.ha.rst b/docs/api/asyncua.client.ha.rst index b17d71f2a..f72f2f9fb 100644 --- a/docs/api/asyncua.client.ha.rst +++ b/docs/api/asyncua.client.ha.rst @@ -36,4 +36,3 @@ asyncua.client.ha.virtual\_subscription module :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.client.rst b/docs/api/asyncua.client.rst index ecc2963da..fdf63439d 100644 --- a/docs/api/asyncua.client.rst +++ b/docs/api/asyncua.client.rst @@ -44,4 +44,3 @@ asyncua.client.ua\_file\_transfer module :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.common.rst b/docs/api/asyncua.common.rst index 2b504dd71..30cbf133a 100644 --- a/docs/api/asyncua.common.rst +++ b/docs/api/asyncua.common.rst @@ -172,4 +172,3 @@ asyncua.common.xmlparser module :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.crypto.rst b/docs/api/asyncua.crypto.rst index 08d798234..feeb5ca1f 100644 --- a/docs/api/asyncua.crypto.rst +++ b/docs/api/asyncua.crypto.rst @@ -25,4 +25,3 @@ asyncua.crypto.uacrypto module :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.server.rst b/docs/api/asyncua.server.rst index 983d03b38..a8a65f66b 100644 --- a/docs/api/asyncua.server.rst +++ b/docs/api/asyncua.server.rst @@ -124,4 +124,3 @@ asyncua.server.users module :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.server.standard_address_space.rst b/docs/api/asyncua.server.standard_address_space.rst index 5e4ef19cf..d1cd63c2a 100644 --- a/docs/api/asyncua.server.standard_address_space.rst +++ b/docs/api/asyncua.server.standard_address_space.rst @@ -20,4 +20,3 @@ asyncua.server.standard\_address\_space.standard\_address\_space\_services modul :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/asyncua.ua.uaerrors.rst b/docs/api/asyncua.ua.uaerrors.rst index 7e2498941..cf5d8cce9 100644 --- a/docs/api/asyncua.ua.uaerrors.rst +++ b/docs/api/asyncua.ua.uaerrors.rst @@ -10,4 +10,3 @@ asyncua.ua.uaerrors package :members: :undoc-members: :show-inheritance: - diff --git a/docs/api/index.rst b/docs/api/index.rst index bca2e552b..708233fb6 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -6,4 +6,4 @@ API Reference .. toctree:: :maxdepth: 4 - asyncua \ No newline at end of file + asyncua diff --git a/docs/index.rst b/docs/index.rst index 6bcd61cb7..40a24e39a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,7 +16,7 @@ Most code is autogenerated from xml specification using same code as the one tha - A simple GUI client is available: https://github.com/FreeOpcUa/opcua-client-gui - Examples: https://github.com/FreeOpcUa/opcua-asyncio/tree/master/examples - Source Code: https://github.com/FreeOpcUa/opcua-asyncio - + .. toctree:: :maxdepth: 2 diff --git a/docs/requirements.txt b/docs/requirements.txt index 4ee1e8b3b..bd3b5d133 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,4 +3,4 @@ pydata-sphinx-theme>=0.9.0 # sphinx-copybutton>=0.5.0 # Optional Dependencies -sphinx-autobuild>=2021.3.14 \ No newline at end of file +sphinx-autobuild>=2021.3.14 diff --git a/docs/usage/client/overview.rst b/docs/usage/client/overview.rst index 46a7021ed..42d6b39d9 100644 --- a/docs/usage/client/overview.rst +++ b/docs/usage/client/overview.rst @@ -24,5 +24,3 @@ Browsing and accessing nodes ============================ .. todo:: Usage of shortcut objects (root, objects, ...) - - diff --git a/docs/usage/common/node-nodeid.rst b/docs/usage/common/node-nodeid.rst index f8d4cb5fb..c311547a3 100644 --- a/docs/usage/common/node-nodeid.rst +++ b/docs/usage/common/node-nodeid.rst @@ -6,7 +6,7 @@ The NodeId Class ================ :class:`asyncua.ua.uatypes.NodeId` objects are used as unique ids for :class:`~asyncua.common.node.Node`'s -and are therefore used on the server and client side to access specific nodes. The two classes +and are therefore used on the server and client side to access specific nodes. The two classes :class:`~asyncua.ua.uatypes.NodeId` and :class:`~asyncua.common.node.Node` should not be confused: The NodeId is the unique identifier of an actual Node. While the NodeId is used to identify a specific node, the Node object can be used to access the underlying data. @@ -17,7 +17,7 @@ A NodeId contains two main pieces of information that allow a unique mapping in The :attr:`~asyncua.ua.uatypes.NodeId.Identifier` and the :attr:`~asyncua.ua.uatypes.NodeId.NamespaceIndex`. In addition there is the :attr:`~asyncua.ua.uatypes.NodeId.NodeIdType` attribute which is used to specify which opc-ua type is used for the Identifier. In addition to the :class:`~asyncua.ua.uatypes.NodeId` -class, there is also the a :class:`~asyncua.ua.uatypes.ExpandedNodeId` which adds the +class, there is also the a :class:`~asyncua.ua.uatypes.ExpandedNodeId` which adds the :attr:`~asyncua.ua.uatypes.ExpandedNodeId.NamespaceUri` and :attr:`~asyncua.ua.uatypes.ExpandedNodeId.ServerIndex` attributes to make the ID unique across different servers and namespaces. @@ -55,7 +55,7 @@ The following keys are supported: ns The ns key will map to the Namespace of the NodeId i, s, g, b - These keys will map to the Identifier of the NodeId. The character specifies the + These keys will map to the Identifier of the NodeId. The character specifies the type: Numeric, String, Guid or Bytes. srv, nsu: If one of this keys is set, a :class:`~asyncua.ua.uatypes.ExpandedNodeId` will be returned @@ -98,11 +98,11 @@ and client side. Therefore, both, the server and client, provide a :code:`get_no :meth:`asyncua.client.client.Client.get_node` & :meth:`asyncua.server.server.Server.get_node`. These functions can be used to get a node by it's NodeId, for example: -.. code-block:: +.. code-block:: >>> client.get_node("ns=2;i=2") Node(NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=)) - + Note that using :code:`get_node` does not check if the node actually exists! The method just creates a new node which later can be used to query data. @@ -111,7 +111,7 @@ just creates a new node which later can be used to query data. The node now can be used to read / write / ... data from the server: -.. code-block:: +.. code-block:: >>> node = client.get_node("ns=2;i=2") >>> name = (await node.read_browse_name()).Name @@ -134,13 +134,13 @@ result in a error as the sent datatype does not match the expected type on the s The node object can also be used to browse to other nodes. There are several methods available as shown in the following short example: -.. code-block:: +.. code-block:: >>> # Get the parent of a node >>> parent = await node.get_parent() >>> print(parent) Node(NodeId(Identifier=1, NamespaceIndex=2, NodeIdType=)) - + >>> # Get all children of a node >>> await parent.get_children() [Node(NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=))] @@ -153,7 +153,7 @@ Note that in the last example we use the browse path of child as argument to :meth:`~asyncua.common.node.Node.get_child`. With the same method it's also possible to access a child several levels deeper than the current node: -.. code-block:: +.. code-block:: >>> await c.nodes.objects.get_child(['2:MyObject', '2:MyVariable']) Node(NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=)) @@ -162,4 +162,4 @@ Here we start at the objects node an traverse via MyObject to MyVariable. Always mind that browsing through the nodes will create network traffic and server load. If you already know the NodeId using :meth:`~asyncua.client.client.Client.get_node` should be preferred. You might also consider caching NodeIds which you found through browsing -to reduce the traffic. +to reduce the traffic. diff --git a/docs/usage/common/overview.rst b/docs/usage/common/overview.rst index 8ede8801b..16607649b 100644 --- a/docs/usage/common/overview.rst +++ b/docs/usage/common/overview.rst @@ -31,5 +31,3 @@ asyncua.crypto package Code related to permissions, security and encryption is located in the :mod:`asyncua.crypto` package. - - diff --git a/docs/usage/get-started/installation.rst b/docs/usage/get-started/installation.rst index 12b5f35d6..7a72b40fb 100644 --- a/docs/usage/get-started/installation.rst +++ b/docs/usage/get-started/installation.rst @@ -25,7 +25,7 @@ Once the installation is completed, the package is ready to be used. To verify t or the report the version if you create a bugreport, the following code can be run in a python interpreter: .. code-block:: python - + import asyncua print(asyncua.__version__) @@ -33,12 +33,12 @@ or the report the version if you create a bugreport, the following code can be r Command Line Tools ================== -Alongside the package some utility command line tools are installed: +Alongside the package some utility command line tools are installed: -:code:`uabrowse`: +:code:`uabrowse`: Browse OPC-UA node and print result -:code:`uacall`: +:code:`uacall`: Call method of a node :code:`uaclient`: diff --git a/docs/usage/get-started/minimal-client.rst b/docs/usage/get-started/minimal-client.rst index 2d763151c..fdbdf5e9b 100644 --- a/docs/usage/get-started/minimal-client.rst +++ b/docs/usage/get-started/minimal-client.rst @@ -33,7 +33,7 @@ Read / Write Variables ====================== To read or write a variable of an object, we first need to get the :class:`~asyncua.common.node.Node` -of the variable. The :meth:`~asyncua.common.node.Node.get_child` method of the root node +of the variable. The :meth:`~asyncua.common.node.Node.get_child` method of the root node (which is just a regular node) is used to transform the known path to a Node. .. note:: Using :meth:`~asyncua.common.node.Node.get_child` will perform a server request @@ -41,7 +41,7 @@ of the variable. The :meth:`~asyncua.common.node.Node.get_child` method of the r create a lot of network traffic which is not strictly required if the node id is known. If you know the node id it's better to use the :meth:`~asyncua.client.client.Client.get_node` method of the client. For example :code:`client.get_node("ns=2;i=2")` or - :code:`client.get_node(ua.NodeId(2, 2))` could be used in the example. + :code:`client.get_node(ua.NodeId(2, 2))` could be used in the example. Note that the latter call is not :code:`async`! Once we have our node object, the variable value can be read or written directly using diff --git a/docs/usage/get-started/minimal-server.rst b/docs/usage/get-started/minimal-server.rst index 56f266629..a7adbeb26 100644 --- a/docs/usage/get-started/minimal-server.rst +++ b/docs/usage/get-started/minimal-server.rst @@ -44,14 +44,14 @@ the server. The following session gives you an idea how the tools can be used. 7.599999999999997 $ uaread --url=opc.tcp://127.0.0.1:4840 --path "0:Objects,2:MyObject,2:MyVariable" # By BrowsePath 12.199999999999996 - + Seems like our server is working and we can browse through the nodes, read values, ... So let's start working through the code! Imports, Basic Setup & Configuration ==================================== -In the first few lines the relevant packages, classes and methods are imported. +In the first few lines the relevant packages, classes and methods are imported. While the :mod:`logging` module is optional (just remove all calls to the logging module), :mod:`asyncio` is required to actually run our main function. From the :mod:`asyncua` package we need the :class:`~asyncua.server.server.Server`, the :mod:`asyncua.ua` @@ -83,7 +83,7 @@ Creating Objects and Variables In the next lines, the custom object "MyObject" is created and a variable is added to this object. Note that by default all variables are read-only, so we need to be explicit and make it writable. The :meth:`~asyncua.common.node.Node.add_object` / :meth:`~asyncua.common.node.Node.add_variable` calls -are actually just calling :meth:`~asyncua.common.manage_nodes.create_object`, respectively +are actually just calling :meth:`~asyncua.common.manage_nodes.create_object`, respectively :meth:`~asyncua.common.manage_nodes.create_variable` internally. You can find more information on how nodes and variables are created in the API docs of these methods. @@ -96,7 +96,7 @@ by clients: .. literalinclude:: ../../../examples/server-minimal.py :caption: server-minimal.py, Line 8 - 11 - :lines: 8 - 11 + :lines: 8 - 11 .. literalinclude:: ../../../examples/server-minimal.py :caption: server-minimal.py, Line 30 - 36 @@ -114,7 +114,7 @@ Starting the Server :caption: server-minimal.py, Line 37 - :lines: 37 - -Using the server as a context manager with :code:`async with server: ...` allows us to +Using the server as a context manager with :code:`async with server: ...` allows us to hide starting and shutting down the server nicely. In order to keep the server alive a endless loop must be present. In this example the loop is also used to periodically update the variable in our custom object. diff --git a/docs/usage/get-started/opc-ua-basics.rst b/docs/usage/get-started/opc-ua-basics.rst index 86dc8a4f2..f70e60622 100644 --- a/docs/usage/get-started/opc-ua-basics.rst +++ b/docs/usage/get-started/opc-ua-basics.rst @@ -2,8 +2,8 @@ OPC-UA Basics ============= -.. todo:: How much should be in this chapter? - +.. todo:: How much should be in this chapter? + Are we only going to link to external references and skip explaining the OPC-UA basics? The `open62541 documentation `_ for example contains a lot of information about how OPC-UA works but in many chapters it also @@ -16,7 +16,7 @@ OPC-UA Basics External References =================== -.. note:: We are open to suggestions for this section! +.. note:: We are open to suggestions for this section! You know good tutorials, help pages, blogs or other resources? Share them with us! @@ -33,4 +33,3 @@ https://www.open62541.org https://www.unified-automation.com Unified Automation provides different products for the OPC-UA ecosystem. Most of the tools are available as a free download with an evaluation license (non commercial use). - diff --git a/docs/usage/index.rst b/docs/usage/index.rst index 5cce72d5c..7e58ff08e 100644 --- a/docs/usage/index.rst +++ b/docs/usage/index.rst @@ -2,7 +2,7 @@ Usage Guide =========== -.. toctree:: +.. toctree:: :maxdepth: 2 :caption: Get started @@ -11,14 +11,14 @@ Usage Guide get-started/minimal-server get-started/minimal-client -.. toctree:: +.. toctree:: :maxdepth: 2 :caption: Common common/overview common/node-nodeid -.. toctree:: +.. toctree:: :maxdepth: 2 :caption: Client @@ -30,7 +30,7 @@ Usage Guide server/overview -.. toctree:: +.. toctree:: :maxdepth: 2 :caption: Sync Interface diff --git a/docs/usage/server/overview.rst b/docs/usage/server/overview.rst index 14a554a47..d665407bb 100644 --- a/docs/usage/server/overview.rst +++ b/docs/usage/server/overview.rst @@ -1,2 +1,2 @@ Server Overview -=============== \ No newline at end of file +=============== diff --git a/docs/usage/sync/overview.rst b/docs/usage/sync/overview.rst index 5d02a0150..a0cec79c8 100644 --- a/docs/usage/sync/overview.rst +++ b/docs/usage/sync/overview.rst @@ -6,4 +6,4 @@ You don't like to work with ``asyncio`` and ``async`` / ``await`` or you need to the package in code which is not using ``asyncio``? The :mod:`asyncua.sync` module provides a convenient wrapper around the client and server and provides synchronous versions of the node and subscription classes. This allows direct usage of the package, using the same -interface as for ``async`` code, without writing custom wrappers. \ No newline at end of file +interface as for ``async`` code, without writing custom wrappers. diff --git a/schemas/README.md b/schemas/README.md index a82a22484..f961b103d 100644 --- a/schemas/README.md +++ b/schemas/README.md @@ -1,12 +1,12 @@ -## How to update the UA-Nodesets from the OPC Foundation +## How to update the UA-Nodesets from the OPC Foundation -1) Have a working internet connection (otherwise it will regenerate the old set or fail) +1) Have a working internet connection (otherwise it will regenerate the old set or fail) 2) run update_ua_nodeset.py 3) That's it -Path to the .pickle file: opcua-asyncio/asyncua/binary_address_space.pickle -Path to the .xml Nodesets: opcua-asyncio/schemas/UA-Nodeset-master/Schema/ -Path to the standard_address_space.py files: opcua-asyncio/asyncua/server/standard_address_space/ +Path to the .pickle file: opcua-asyncio/asyncua/binary_address_space.pickle +Path to the .xml Nodesets: opcua-asyncio/schemas/UA-Nodeset-master/Schema/ +Path to the standard_address_space.py files: opcua-asyncio/asyncua/server/standard_address_space/ ##Warnings: @@ -16,4 +16,3 @@ Path to the standard_address_space.py files: opcua-asyncio/asyncua/server/standa - our Github Discussions: https://github.com/FreeOpcUa/opcua-asyncio/discussions - our Gitter Channel: https://gitter.im/FreeOpcUa/opcua-asyncio - in case of Bugs with the updater, please make an issue: https://github.com/FreeOpcUa/opcua-asyncio/issues - \ No newline at end of file diff --git a/schemas/generate_model_event.py b/schemas/generate_model_event.py index 0147411c9..9099ea56b 100644 --- a/schemas/generate_model_event.py +++ b/schemas/generate_model_event.py @@ -66,8 +66,8 @@ def findNodeWithNodeId(self, root, nodeId): node = Node_struct() for child in root: if nodeId == child.attrib.get('NodeId'): - # The xml-tag is the type of an xml-element e.g. then tag is Reference. - # The tag also includes the namespace which needs to be removed + # The xml-tag is the type of an xml-element e.g. then tag is Reference. + # The tag also includes the namespace which needs to be removed # e.g. '{http://opcfoundation.org/UA/2011/03/UANodeSet.xsd}Reference' node.tag = child.tag.split(self.nameSpace)[1] node.browseName = str(child.attrib.get('BrowseName')) diff --git a/schemas/generate_protocol_python.py b/schemas/generate_protocol_python.py index 07270faa9..4d9b59e43 100644 --- a/schemas/generate_protocol_python.py +++ b/schemas/generate_protocol_python.py @@ -218,7 +218,7 @@ def get_default_value(self, field): if __name__ == '__main__': import generate_model_from_nodeset as gm - xml_path = BASE_DIR.joinpath('schemas', 'UA-Nodeset-master', 'Schema', 'Opc.Ua.NodeSet2.Services.xml') + xml_path = BASE_DIR.joinpath('schemas', 'UA-Nodeset-master', 'Schema', 'Opc.Ua.NodeSet2.Services.xml') protocol_path = BASE_DIR.joinpath("asyncua", "ua", "uaprotocol_auto.py") p = gm.Parser(xml_path) model = p.parse() diff --git a/tests/custom_extension_with_optional_fields.xml b/tests/custom_extension_with_optional_fields.xml index a55677d63..953dd2845 100644 --- a/tests/custom_extension_with_optional_fields.xml +++ b/tests/custom_extension_with_optional_fields.xml @@ -74,4 +74,4 @@ - \ No newline at end of file + diff --git a/tests/custom_nodes.xml b/tests/custom_nodes.xml index a77bbce55..4e93fc28d 100644 --- a/tests/custom_nodes.xml +++ b/tests/custom_nodes.xml @@ -51,26 +51,26 @@ - + i=69 ns=1;i=30002 - + MyCustomString i=12 - + i=69 ns=1;i=30002 - + MyEnum @@ -85,7 +85,7 @@ - + EnumStrings @@ -107,8 +107,8 @@ - - + + MyEnumVal @@ -120,7 +120,7 @@ - + EnumValues @@ -323,6 +323,6 @@ - - + + diff --git a/tests/custom_nodesns.xml b/tests/custom_nodesns.xml index 48f8a0c38..5f700b216 100644 --- a/tests/custom_nodesns.xml +++ b/tests/custom_nodesns.xml @@ -135,7 +135,7 @@ MyBaseObject i=85 - ns=1;i=6001 + ns=1;i=6001 @@ -147,5 +147,5 @@ 0 - + diff --git a/tests/custom_nodesns_2.xml b/tests/custom_nodesns_2.xml index ca8b9a8bc..0c970859b 100644 --- a/tests/custom_nodesns_2.xml +++ b/tests/custom_nodesns_2.xml @@ -137,7 +137,7 @@ MyBaseObject ns=2;i=5002 - ns=1;i=6001 + ns=1;i=6001 @@ -149,5 +149,5 @@ 0 - + diff --git a/tests/custom_nodesns_3.xml b/tests/custom_nodesns_3.xml index 6c60dc416..45ff949d3 100644 --- a/tests/custom_nodesns_3.xml +++ b/tests/custom_nodesns_3.xml @@ -150,5 +150,5 @@ 0 - + diff --git a/tests/custom_nodesns_4.xml b/tests/custom_nodesns_4.xml index 7d2074cd6..ee52ce187 100644 --- a/tests/custom_nodesns_4.xml +++ b/tests/custom_nodesns_4.xml @@ -141,10 +141,10 @@ MyBaseObject ns=3;i=5002 - ns=1;i=6001 + ns=1;i=6001 - + MyVar @@ -154,5 +154,5 @@ 0 - + diff --git a/tests/example.bsd b/tests/example.bsd index bb7b325a0..cfb06176f 100644 --- a/tests/example.bsd +++ b/tests/example.bsd @@ -234,4 +234,4 @@ - \ No newline at end of file + diff --git a/tools/uaserver b/tools/uaserver index dcabedc67..c2e3f9fb7 100755 --- a/tools/uaserver +++ b/tools/uaserver @@ -7,7 +7,7 @@ from pathlib import Path logging.basicConfig(level=logging.DEBUG) sys.path.append(f'{Path(__file__).parent.parent}') -from asyncua.tools import uaserver +from asyncua.tools import uaserver # noqa: E402 if __name__ == "__main__": uaserver()