Skip to content

Commit

Permalink
Add pre-commit-config
Browse files Browse the repository at this point in the history
  • Loading branch information
rth committed Oct 15, 2024
1 parent 1343fa7 commit 73175b9
Show file tree
Hide file tree
Showing 41 changed files with 131 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ updates:
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
interval: "weekly"
25 changes: 18 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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/.*
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
path: .
24 changes: 12 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()`.
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion asyncua/common/xmlimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

Expand Down
2 changes: 0 additions & 2 deletions asyncua/ua/uaerrors/_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,5 +857,3 @@ class BadMaxConnectionsReached(UaStatusCodeError):

class BadDataSetIdInvalid(UaStatusCodeError):
code = 0x80E70000


2 changes: 1 addition & 1 deletion asyncua/ua/uaprotocol_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/api/asyncua.client.ha.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ asyncua.client.ha.virtual\_subscription module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ asyncua.client.ua\_file\_transfer module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,3 @@ asyncua.common.xmlparser module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.crypto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ asyncua.crypto.uacrypto module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,3 @@ asyncua.server.users module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.server.standard_address_space.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ asyncua.server.standard\_address\_space.standard\_address\_space\_services modul
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion docs/api/asyncua.ua.uaerrors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ asyncua.ua.uaerrors package
:members:
:undoc-members:
:show-inheritance:

2 changes: 1 addition & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ API Reference
.. toctree::
:maxdepth: 4

asyncua
asyncua
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pydata-sphinx-theme>=0.9.0
# sphinx-copybutton>=0.5.0

# Optional Dependencies
sphinx-autobuild>=2021.3.14
sphinx-autobuild>=2021.3.14
2 changes: 0 additions & 2 deletions docs/usage/client/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ Browsing and accessing nodes
============================

.. todo:: Usage of shortcut objects (root, objects, ...)


20 changes: 10 additions & 10 deletions docs/usage/common/node-nodeid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=<NodeIdType.Numeric: 2>))
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.

Expand All @@ -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
Expand All @@ -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=<NodeIdType.FourByte: 1>))
>>> # Get all children of a node
>>> await parent.get_children()
[Node(NodeId(Identifier=2, NamespaceIndex=2, NodeIdType=<NodeIdType.FourByte: 1>))]
Expand All @@ -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=<NodeIdType.FourByte: 1>))
Expand All @@ -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.
2 changes: 0 additions & 2 deletions docs/usage/common/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ asyncua.crypto package

Code related to permissions, security and encryption is located in the :mod:`asyncua.crypto`
package.


8 changes: 4 additions & 4 deletions docs/usage/get-started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ 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__)
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`:
Expand Down
Loading

0 comments on commit 73175b9

Please sign in to comment.