Skip to content

Commit

Permalink
Use ruff for linting (#60)
Browse files Browse the repository at this point in the history
* use ruff instead of black for formatting

* handle linter
  • Loading branch information
lobis authored Aug 26, 2024
1 parent e6bb0e5 commit 08962b2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ repos:
- id: pretty-format-json
args: [ --autofix ]

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.2
hooks:
- id: ruff
args: [ "--fix-only" , "--show-fixes" ]
args: [ "--fix" , "--show-fixes" ] # --fix-only

- id: ruff-format
6 changes: 3 additions & 3 deletions src/hvps/commands/iseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def _parse_response(
except UnicodeDecodeError:
raise ValueError(f"Invalid response: {response}")

if expected_response_type == float or expected_response_type == List[float]:
if expected_response_type is float or expected_response_type is List[float]:
# pattern for a float in scientific notation followed or not by units
pattern = (
r"^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?(\s*[a-zA-Z%]+(/+[a-zA-Z]+)?)?$"
)
elif expected_response_type == int or expected_response_type == List[int]:
elif expected_response_type is int or expected_response_type is List[int]:
pattern = r"^[-+]?\d+(\s*[a-zA-Z]+(/+[a-zA-Z]+)?)?$"
elif expected_response_type == str or expected_response_type == List[str]:
elif expected_response_type is str or expected_response_type is List[str]:
pattern = r"^[\x00-\x7F]+$"
elif expected_response_type is None:
split_response = response.split(",")
Expand Down
4 changes: 1 addition & 3 deletions src/hvps/devices/iseg/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ def module_can_bitrate(self) -> int:
@property
def serial_baud_rate(
self,
) -> (
int
): # Instruction is currently implemented for EHS devices with serial interface only
) -> int: # Instruction is currently implemented for EHS devices with serial interface only
"""Query the device's serial baud rate.
Returns:
Expand Down
4 changes: 3 additions & 1 deletion src/hvps/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .utils import *
# TODO: avoid using noqa and provide a better solution

from .utils import * # noqa: F403
10 changes: 5 additions & 5 deletions src/hvps/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def check_command_input(
raise ValueError(f"Method {method} does not take an input value.")
else:
return
if input_type == str:
if input_type is str:
if not isinstance(input_value, str):
raise ValueError(
f"Value {input_value} must be a string. Got {type(input_value)} instead."
)
if input_type == int or input_type == float:
if input_type is int or input_type is float:
if not isinstance(input_value, (int, float)):
raise ValueError(
f"Value {input_value} must be a number. Got {type(input_value)} instead."
Expand Down Expand Up @@ -137,22 +137,22 @@ def check_command_output_and_convert(
else:
return None
else:
if output_type == float or output_type == int:
if output_type is float or output_type is int:
try:
value = output_type(remove_units(response))
except ValueError:
raise ValueError(
f"Invalid string '{response}'. Must be a {output_type}."
)
elif output_type == List[float]:
elif output_type is List[float]:
response = response.split(",")
try:
value = [float(remove_units(v)) for v in response]
except ValueError:
raise ValueError(
f"Invalid string '{response}'. Must be a list of float."
)
elif output_type == List[int]:
elif output_type is List[int]:
try:
response = response.split(",")
value = [int(v) for v in response]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_iseg_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ def test_iseg_channel_monitor():
# TODO: validate the values (atleast check if they are not None)
# TODO: Do the same for CAEN

iseg = Iseg(
port=serial_port,
baudrate=serial_baud,
connect=True,
timeout=timeout,
logging_level=logging.DEBUG,
)
iseg.connect()

print(
f"Serial port status: connected: {iseg.connected}, port: {iseg.port}, baudrate: {iseg.baudrate}, timeout: {iseg.timeout}"
)
module = iseg.module(0)
channel = module.channel(0)

trip_action = channel.trip_action
print(f"trip_action: {trip_action}")

Expand Down

0 comments on commit 08962b2

Please sign in to comment.