Skip to content

Commit

Permalink
Merge pull request #23 from numat/ruff
Browse files Browse the repository at this point in the history
Switch from flake8 to ruff
  • Loading branch information
alexrudd2 authored Apr 10, 2023
2 parents b7ffe31 + abc52b7 commit 45e6157
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,3 @@ proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ steps:
pip install '.[test]'
displayName: 'Install dependencies'

- script: |
ruff .
displayName: 'Lint code with ruff'

- script: |
cd watlow
pytest --junitxml=../reports/test-coverage.xml --cov=. --cov-report=xml
Expand Down
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"config:base"
],
"timezone": "America/Chicago"
}
17 changes: 17 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
line-length = 99
ignore = [
"PLR2004",
"D104",
"D107",
"C901",
]
exclude = ["venv*"]
select = ["C", "D", "E", "F", "I", "UP", "YTT", "W"]
# "SIM" flake-simplify
# "ARG" flake8-unused args
# "B" bandit
# "RUF" ruff base config
[pydocstyle]
convention = "pep257"
[flake8-unused-arguments]
ignore-variadic-names = true
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
[flake8]
max-complexity = 15
max-line-length = 99
docstring-convention = pep257

# no docstrings in __init__.py
ignore = D104,D107,W503

[mypy]
check_untyped_defs = True
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from setuptools import setup

if version_info < (3, 7):
if version_info < (3, 7): # noqa: UP036
raise ImportError("This module requires Python >=3.7. Use 0.3.1 for Python3.6")

with open('README.md', 'r') as in_file:
with open('README.md') as in_file:
long_description = in_file.read()

setup(
Expand All @@ -31,6 +31,7 @@
'pytest',
'pytest-cov',
'pytest-asyncio',
'ruff==0.0.261',
],
},
entry_points={
Expand Down
17 changes: 9 additions & 8 deletions watlow/driver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Drivers for Watlow EZ-Zone temperature controllers."""
from __future__ import annotations

import logging
import re
import struct
from binascii import unhexlify
from typing import Dict, Union

import crcmod # type: ignore
import serial
Expand All @@ -29,7 +30,7 @@ def c_to_f(c):
return c * 1.8 + 32.0


class TemperatureController(object):
class TemperatureController:
"""Driver for the Watlow EZ-ZONE temperature controller.
This driver borrows heavily from this StackOverflow post:
Expand Down Expand Up @@ -61,13 +62,13 @@ class TemperatureController(object):
commands = {
'actual':
{'header': unhexlify('0510000006'),
'body': unhexlify('010301040101')}, # noqa: E241
'body': unhexlify('010301040101')},
'setpoint':
{'header': unhexlify('0510000006'),
'body': unhexlify('010301070101')}, # noqa: E241
'body': unhexlify('010301070101')},
'set':
{'header': unhexlify('051000000a'),
'body': unhexlify('010407010108')}, # noqa: E241
'body': unhexlify('010407010108')},
}
responses = {
'actual': re.compile('^55ff060010000b8802030104010108'
Expand Down Expand Up @@ -138,7 +139,7 @@ def set(self, setpoint):

# check setpoint versus response, if not the same raise an error
if round(setpoint, 2) != round(response, 2):
raise IOError(f"Could not change setpoint from "
raise OSError(f"Could not change setpoint from "
f"{response:.2f}°C to {setpoint:.2f}°C.")

def _write_and_read(self, request, length, check, retries=3):
Expand All @@ -157,7 +158,7 @@ def _write_and_read(self, request, length, check, retries=3):
self.open()
if retries <= 0:
self.close()
raise IOError("Could not communicate with Watlow.")
raise OSError("Could not communicate with Watlow.")
self.connection.flush()
try:
logging.debug('Formatted Request: ' + str(bytes.hex(request)))
Expand Down Expand Up @@ -194,7 +195,7 @@ async def get(self, zone: int):
For more information on a 'Zone', refer to Watlow manuals.
"""
output: Dict[str, Union[int, None]] = {
output: dict[str, int | None] = {
'actual': self.actual_temp_address,
'setpoint': self.setpoint_address,
'output': self.output_address,
Expand Down
7 changes: 4 additions & 3 deletions watlow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from pymodbus.client import AsyncModbusTcpClient # 3.x
except ImportError: # 2.4.x - 2.5.x
from pymodbus.client.asynchronous.async_io import ( # type: ignore
ReconnectingAsyncioModbusTcpClient)
ReconnectingAsyncioModbusTcpClient,
)
import pymodbus.exceptions


class AsyncioModbusClient(object):
class AsyncioModbusClient:
"""A generic asyncio client.
This expands upon the pymodbus AsyncModbusTcpClient by
Expand Down Expand Up @@ -48,7 +49,7 @@ async def _connect(self):
except AttributeError: # 2.4.x - 2.5.x
await self.client.start(self.ip) # type: ignore
except Exception:
raise IOError(f"Could not connect to '{self.ip}'.")
raise OSError(f"Could not connect to '{self.ip}'.")

async def read_coils(self, address, count):
"""Read modbus output coils (0 address prefix)."""
Expand Down

0 comments on commit 45e6157

Please sign in to comment.