Skip to content

Commit

Permalink
added ruff linter to workflow, fixed linting errors in all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Weidauer committed Sep 13, 2024
1 parent 2cacaaf commit 312c22d
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
pip install pytest pyfar
pip install .
- name: Lint with Ruff
run: |
pip install ruff
ruff check --output-format=github .
- name: Run tests
run: |
pip install pytest pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion src/osc_kreuz/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def read_config(config_path) -> dict:
break

if config_path is None:
log.warning(f"Could not find config, loading default config")
log.warning("Could not find config, loading default config")
# load the default config embedded into this package using files
config_path = files("osc_kreuz").joinpath("config_default.yml")
config = yaml.load(config_path.read_bytes(), Loader=yaml.Loader)
Expand Down
6 changes: 2 additions & 4 deletions src/osc_kreuz/conversionsTools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

import numpy as np


Expand All @@ -11,7 +9,7 @@ def mag_xyz(x, y, z) -> float:


def aed2xyz(a, e, d, coordinates_in_degree: bool = True) -> list[float]:
if coordinates_in_degree == True:
if coordinates_in_degree:
e = np.deg2rad(e)
a = np.deg2rad(a)

Expand All @@ -28,7 +26,7 @@ def xyz2aed(x, y, z, coordinates_in_degree: bool = True) -> list[float]:
azim = np.arctan2(y, x)
elev = np.arctan2(z, np.sqrt(np.square(x) + np.square(y)))

if coordinates_in_degree == True:
if coordinates_in_degree:
azim = np.rad2deg(azim)
elev = np.rad2deg(elev)

Expand Down
3 changes: 1 addition & 2 deletions src/osc_kreuz/osc_kreuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from threading import Event

import click
import yaml

from osc_kreuz.config import read_config, read_config_option
import osc_kreuz.osccomcenter as osccomcenter
Expand Down Expand Up @@ -167,7 +166,7 @@ def main(config_path, oscdebug, verbose, ip, port_ui, port_data, port_settings):
log.info("setting up receivers")
if "receivers" in config:
for receiver_config in config["receivers"]:
if not "type" in receiver_config:
if "type" not in receiver_config:
log.warning("receiver has no type specified, skipping")
continue
try:
Expand Down
25 changes: 12 additions & 13 deletions src/osc_kreuz/osccomcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def oscreceived_pong(self, *args):
try:
clientName = args[0]
self.clientSubscriptions[clientName].receivedIsAlive()
except:
except Exception:
if self.verbosity > 0:
_name = ""
if len(args) > 0:
Expand Down Expand Up @@ -132,15 +132,15 @@ def oscreceived_subscriptionRequest(self, *args) -> None:
# viewClientInitValues[initKeys[i-2]] = args[i]
try:
viewClientInitValues["dataformat"] = args[2].decode()
except:
except KeyError:
pass
try:
viewClientInitValues["indexAsValue"] = args[3]
except:
except KeyError:
pass
try:
viewClientInitValues["updateintervall"] = args[4]
except:
except KeyError:
pass
newViewClient = ViewClient(vCName, **viewClientInitValues)

Expand All @@ -162,7 +162,6 @@ def osc_handler_unsubscribe(self, *args) -> None:
args[0] nameFor Client
"""
log.info("unsubscribe request")
subArgs = len(args)
if len(args) >= 1:
client_name = args[0]
try:
Expand Down Expand Up @@ -191,7 +190,7 @@ def deleteClient(self, viewC, alias):
log.warning(f"tried to delete receiver {alias}, but it does not exist")

def checkPort(self, port) -> bool:
if type(port) == int and 1023 < port < 65535:
if type(port) is int and 1023 < port < 65535:
return True
else:
if self.verbosity > 0:
Expand All @@ -203,7 +202,7 @@ def checkIp(self, ip) -> bool:
try:
_ip = "127.0.0.1" if ip == "localhost" else ip
_ = ipaddress.ip_address(_ip)
except:
except Exception:
ipalright = False
if self.verbosity > 0:
log.info(f"ip address {ip} not legit")
Expand Down Expand Up @@ -232,7 +231,7 @@ def oscreceived_debugOscCopy(self, *args):
ip = "127.0.0.1" if ip == "localhost" else ip
osccopy_ip = ipaddress.ip_address(ip)
osccopy_port = int(port)
except:
except Exception:
log.info("debug client: invalid ip or port")
return
log.info(f"debug client connected: {ip}:{port}")
Expand All @@ -248,7 +247,7 @@ def oscreceived_verbose(self, *args):
vvvv = -1
try:
vvvv = int(args[0])
except:
except Exception:
self.setVerbosity(0)
# verbosity = 0
# Renderer.setVerbosity(0)
Expand Down Expand Up @@ -466,7 +465,7 @@ def sourceLegit(self, id: int) -> bool:
indexInRange = 0 <= id < self.n_sources
if self.verbosity > 0:
if not indexInRange:
if not type(id) == int:
if type(id) is not int:
log.warning("source index is no integer")
else:
log.warning("source index out of range")
Expand All @@ -476,7 +475,7 @@ def renderIndexLegit(self, id: int) -> bool:
indexInRange = 0 <= id < self.n_renderengines
if self.verbosity > 0:
if not indexInRange:
if not type(id) == int:
if type(id) is not int:
log.warning("renderengine index is no integer")
else:
log.warning("renderengine index out of range")
Expand All @@ -486,7 +485,7 @@ def directSendLegit(self, id: int) -> bool:
indexInRange = 0 <= id < self.n_direct_sends
if self.verbosity > 0:
if not indexInRange:
if not type(id) == int:
if type(id) is not int:
log.warning("direct send index is no integer")
else:
log.warning("direct send index out of range")
Expand Down Expand Up @@ -602,7 +601,7 @@ def osc_handler_attribute(
except ValueError:
return False

if attribute == None:
if attribute is None:
try:
attribute = skc.SourceAttributes(args[args_index])
args_index += 1
Expand Down
14 changes: 7 additions & 7 deletions src/osc_kreuz/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def send_updates(self, msgs):
receiversClient.send_message(msg.path, msg.values)

except Exception as e:
log.warn(
log.warning(
f"Exception while sending to {receiversClient.address}:{receiversClient.port}: {e}"
)

Expand All @@ -315,7 +315,7 @@ def send_updates(self, msgs):
).encode()
try:
self.oscDebugClient.send_message(debugOsc, msg.values)
except:
except Exception:
pass

if self.printOutput:
Expand Down Expand Up @@ -367,9 +367,9 @@ def sourcePositionChanged(self, source_idx):

class Wonder(SpatialRenderer):
def __init__(self, **kwargs):
if not "dataformat" in kwargs.keys():
if "dataformat" not in kwargs.keys():
kwargs["dataformat"] = "xy"
if not "sourceattributes" in kwargs.keys():
if "sourceattributes" not in kwargs.keys():
kwargs["sourceattributes"] = (
skc.SourceAttributes.doppler,
skc.SourceAttributes.planewave,
Expand Down Expand Up @@ -566,7 +566,7 @@ def __init__(self, paths: Iterable[dict["str", Any]], **kwargs):
elif path_type in ["position", "pos"]:
try:
coord_fmt = path["format"]
except:
except KeyError:
coord_fmt = "xyz"
self.pos_paths.append((osc_path.encode(), coord_fmt))

Expand Down Expand Up @@ -630,7 +630,7 @@ def sourcePositionChanged(self, source_idx):

class SuperColliderEngine(SpatialRenderer):
def __init__(self, **kwargs):
if not "dataformat" in kwargs.keys():
if "dataformat" not in kwargs.keys():
kwargs["dataformat"] = "aed"
super(SuperColliderEngine, self).__init__(**kwargs)

Expand Down Expand Up @@ -904,7 +904,7 @@ def my_type(self) -> str:
return "Seamless Plugin"

def __init__(self, **kwargs):
if not "dataformat" in kwargs.keys():
if "dataformat" not in kwargs.keys():
kwargs["dataformat"] = "xyz"
super(SeamlessPlugin, self).__init__(**kwargs)

Expand Down
2 changes: 0 additions & 2 deletions src/osc_kreuz/soundobject.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from functools import partial
from time import time

import numpy as np

import osc_kreuz.conversionsTools as ct
from osc_kreuz.coordinates import (
Coordinate,
CoordinateCartesian,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def test_simple_conversions():
((90, 0, 1), (0, 1, 0)),
((0, 90, 2), (0, 0, 2)),
]:
xyz_calc = ct.conv_pol2cart(*aed)
xyz_calc = ct.aed2xyz(*aed)
assert np.allclose(xyz, xyz_calc)
aed_calc = ct.conv_cart2pol(*xyz_calc)
aed_calc = ct.xyz2aed(*xyz_calc, coordinates_in_degree=True)
assert np.allclose(aed, aed_calc)


Expand All @@ -22,7 +22,7 @@ def test_conversions_xyz_wraparound():
((0, 0, 1), (0, 90, 1)),
((0, 0, -1), (0, -90, 1)),
]:
aed_calc = ct.conv_cart2pol(*xyz)
aed_calc = ct.xyz2aed(*xyz, coordinates_in_degree=True)
assert np.allclose(aed, aed_calc)


Expand All @@ -35,7 +35,7 @@ def test_conversions_aed_wraparound():
((-360, 0, 1), (1, 0, 0)),
((-450, 0, 1), (0, -1, 0)),
]:
xyz_calc = ct.conv_pol2cart(*aed)
xyz_calc = ct.aed2xyz(*aed)
assert np.allclose(xyz, xyz_calc)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_osc_kreuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def osc_callback(*args):
sender.send_message(path.encode(), args)
val = something_changed.wait(5)

assert val == True
assert val
# standard epsilon is to fine grained
assert math.isclose(
listener.sources[source_index].gain[renderer],
Expand Down Expand Up @@ -303,7 +303,7 @@ def osc_callback(*args):
sender.send_message(path.encode(), args)
val = something_changed.wait(5)

assert val == True
assert val
# standard epsilon is to fine grained

assert np.allclose(
Expand Down Expand Up @@ -419,7 +419,7 @@ def osc_callback(*args):
sender.send_message(path.encode(), osc_args)
val = something_changed.wait(5)

assert val == True
assert val

received_xyz = (
listener.sources[source_index].x,
Expand Down Expand Up @@ -509,7 +509,7 @@ def osc_callback(*args):

changed = something_changed.wait()

assert changed == True
assert changed
assert math.isclose(
listener.sources[source_index].direct_sends[direct_send_index],
gain,
Expand Down Expand Up @@ -599,7 +599,7 @@ def osc_callback(*args):

changed = something_changed.wait()

assert changed == True
assert changed
assert math.isclose(
listener.sources[source_index].attributes[attribute],
val,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def test_audiorouter_renderer():
conf = {"type": "audiorouter", "hosts": [], "updateintervall": 5}
c = prepare_renderer(conf)
s = c.updateStack[0]
so = c.sources[0]
assert len(s) == 0
assert isinstance(c, r.Audiorouter)

Expand All @@ -219,7 +218,6 @@ def test_audiorouterWFS_renderer():
conf = {"type": "audiorouterWFS", "hosts": [], "updateintervall": 5}
c = prepare_renderer(conf)
s = c.updateStack[0]
so = c.sources[0]
assert len(s) == 0
assert isinstance(c, r.AudiorouterWFS)

Expand Down

0 comments on commit 312c22d

Please sign in to comment.