diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 577913a..be87000 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -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 diff --git a/src/osc_kreuz/config.py b/src/osc_kreuz/config.py index d65449b..ed54144 100644 --- a/src/osc_kreuz/config.py +++ b/src/osc_kreuz/config.py @@ -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) diff --git a/src/osc_kreuz/conversionsTools.py b/src/osc_kreuz/conversionsTools.py index 57ac5fc..bce47c4 100644 --- a/src/osc_kreuz/conversionsTools.py +++ b/src/osc_kreuz/conversionsTools.py @@ -1,5 +1,3 @@ -from typing import Any - import numpy as np @@ -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) @@ -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) diff --git a/src/osc_kreuz/osc_kreuz.py b/src/osc_kreuz/osc_kreuz.py index 38b0b3d..44f0429 100644 --- a/src/osc_kreuz/osc_kreuz.py +++ b/src/osc_kreuz/osc_kreuz.py @@ -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 @@ -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: diff --git a/src/osc_kreuz/osccomcenter.py b/src/osc_kreuz/osccomcenter.py index 35f0033..a14c707 100644 --- a/src/osc_kreuz/osccomcenter.py +++ b/src/osc_kreuz/osccomcenter.py @@ -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: @@ -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) @@ -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: @@ -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: @@ -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") @@ -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}") @@ -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) @@ -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") @@ -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") @@ -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") @@ -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 diff --git a/src/osc_kreuz/renderer.py b/src/osc_kreuz/renderer.py index 4b37fa2..26bc7d8 100644 --- a/src/osc_kreuz/renderer.py +++ b/src/osc_kreuz/renderer.py @@ -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}" ) @@ -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: @@ -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, @@ -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)) @@ -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) @@ -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) diff --git a/src/osc_kreuz/soundobject.py b/src/osc_kreuz/soundobject.py index bddf0e8..6f8ecc4 100644 --- a/src/osc_kreuz/soundobject.py +++ b/src/osc_kreuz/soundobject.py @@ -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, diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 2d1bebf..fbed64d 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -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) @@ -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) @@ -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) diff --git a/tests/test_osc_kreuz.py b/tests/test_osc_kreuz.py index aa6cccf..04523c6 100644 --- a/tests/test_osc_kreuz.py +++ b/tests/test_osc_kreuz.py @@ -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], @@ -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( @@ -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, @@ -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, @@ -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, diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 3f8a87e..eab9b1c 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -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) @@ -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)