Skip to content

Commit

Permalink
FIX: Activate more linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Nov 27, 2024
1 parent 62588e1 commit b85a9c3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion MethodicConfigurator/annotate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from typing import Any, Optional, Union
from xml.etree import ElementTree as ET # no parsing, just data-structure manipulation

from defusedxml import ElementTree as DET # just parsing, no data-structure manipulation
from defusedxml import ElementTree as DET # noqa: N814, just parsing, no data-structure manipulation

# URL of the XML file
BASE_URL = "https://autotest.ardupilot.org/Parameters/"
Expand Down
2 changes: 1 addition & 1 deletion MethodicConfigurator/backend_flightcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def write(self, _buf) -> NoReturn: # noqa: ANN001
msg = "write always fails"
raise Exception(msg) # pylint: disable=broad-exception-raised

def inWaiting(self) -> int: # pylint: disable=invalid-name
def inWaiting(self) -> int: # noqa: N802, pylint: disable=invalid-name
return 0

def close(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion MethodicConfigurator/backend_mavftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections.abc import Generator
from datetime import datetime
from io import BufferedReader, BufferedWriter
from io import BytesIO as SIO
from io import BytesIO as SIO # noqa: N814
from typing import Union

from pymavlink import mavutil
Expand Down
2 changes: 1 addition & 1 deletion MethodicConfigurator/frontend_tkinter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from logging import warning as logging_warning
from platform import system as platform_system
from tkinter import BooleanVar, messagebox, ttk
from tkinter import font as tkFont
from tkinter import font as tkFont # noqa: N812
from typing import Optional, Union

from PIL import Image, ImageTk
Expand Down
30 changes: 15 additions & 15 deletions MethodicConfigurator/tempcal_imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def __init__(self) -> None:
self.accel: dict[int, dict[str, np.ndarray]] = {}
self.gyro: dict[int, dict[str, np.ndarray]] = {}

def IMUs(self) -> list[int]:
def IMUs(self) -> list[int]: # noqa: N802
"""Return list of IMUs."""
if len(self.accel.keys()) != len(self.gyro.keys()):
print("accel and gyro data doesn't match")
Expand Down Expand Up @@ -242,7 +242,7 @@ def moving_average(self, data: np.ndarray, w: int) -> np.ndarray:
ret[w:] = ret[w:] - ret[:-w]
return ret[w - 1 :] / w

def FilterArray(self, data: dict[str, np.ndarray], width_s: int) -> dict[str, np.ndarray]:
def filter_array(self, data: dict[str, np.ndarray], width_s: int) -> dict[str, np.ndarray]:
"""Apply moving average filter of width width_s seconds."""
nseconds = data["time"][-1] - data["time"][0]
nsamples = len(data["time"])
Expand All @@ -252,11 +252,11 @@ def FilterArray(self, data: dict[str, np.ndarray], width_s: int) -> dict[str, np
data[axis] = self.moving_average(data[axis], window)
return data

def Filter(self, width_s: int) -> None:
def filter(self, width_s: int) -> None:
"""Apply moving average filter of width width_s seconds."""
for imu in self.IMUs():
self.accel[imu] = self.FilterArray(self.accel[imu], width_s)
self.gyro[imu] = self.FilterArray(self.gyro[imu], width_s)
self.accel[imu] = self.filter_array(self.accel[imu], width_s)
self.gyro[imu] = self.filter_array(self.gyro[imu], width_s)

def accel_at_temp(self, imu: int, axis: str, temperature: float) -> float:
"""Return the accel value closest to the given temperature."""
Expand Down Expand Up @@ -289,7 +289,7 @@ def constrain(value: float, minv: float, maxv: float) -> Union[float, int]:
return max(maxv, value)


def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments, too-many-positional-arguments
def IMUfit( # noqa: PLR0915, N802, pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments, too-many-positional-arguments
logfile: str,
outfile: str,
no_graph: bool,
Expand Down Expand Up @@ -421,17 +421,17 @@ def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches,
if msg_type == "TCLR" and tclr:
imu = msg.I

T = msg.Temp
temp = msg.Temp
if msg.SType == 0:
# accel
acc = Vector3(msg.X, msg.Y, msg.Z)
time = msg.TimeUS * 1.0e-6
data.add_accel(imu, T, time, acc)
data.add_accel(imu, temp, time, acc)
elif msg.SType == 1:
# gyro
gyr = Vector3(msg.X, msg.Y, msg.Z)
time = msg.TimeUS * 1.0e-6
data.add_gyro(imu, T, time, gyr)
data.add_gyro(imu, temp, time, gyr)
continue

if msg_type == "IMU" and not tclr:
Expand All @@ -440,7 +440,7 @@ def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches,
if stop_capture[imu]:
continue

T = msg.T
temp = msg.T
acc = Vector3(msg.AccX, msg.AccY, msg.AccZ)
gyr = Vector3(msg.GyrX, msg.GyrY, msg.GyrZ)

Expand All @@ -453,12 +453,12 @@ def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches,
sys.exit(1)

if c.enable[imu] == 1:
acc -= c.correction_accel(imu, T)
gyr -= c.correction_gyro(imu, T)
acc -= c.correction_accel(imu, temp)
gyr -= c.correction_gyro(imu, temp)

time = msg.TimeUS * 1.0e-6
data.add_accel(imu, T, time, acc)
data.add_gyro(imu, T, time, gyr)
data.add_accel(imu, temp, time, acc)
data.add_gyro(imu, temp, time, gyr)

if len(data.IMUs()) == 0:
print("No data found")
Expand All @@ -470,7 +470,7 @@ def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches,
progress_callback(210)
if not tclr:
# apply moving average filter with 2s width
data.Filter(2)
data.filter(2)

c, clog = generate_calibration_file(outfile, online, progress_callback, data, c)

Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ lint.ignore = [
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR2004", # Magic value used in comparison, consider replacing `X` with a constant variable
"N802", # Function name `X` should be lowercase
"N806", # Variable name `X` should be lowercase
"N812", # Lowercase `x` imported as non-lowercase `X`
"N814", # Camelcase `X` imported as constant `Y`
"N817", # CamelCase `X` imported as acronym `Y`
"N999", # Invalid module name: 'MethodicConfigurator'
"ISC001", # to let formatter run
"ANN002",
Expand Down
2 changes: 1 addition & 1 deletion unittests/annotate_params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from xml.etree import ElementTree as ET # no parsing, just data-structure manipulation

import requests # type: ignore[import-untyped]
from defusedxml import ElementTree as DET # just parsing, no data-structure manipulation
from defusedxml import ElementTree as DET # noqa: N814, just parsing, no data-structure manipulation

from MethodicConfigurator.annotate_params import (
BASE_URL,
Expand Down
6 changes: 3 additions & 3 deletions unittests/extract_param_defaults_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_output_params_qgcs_2_4(self, mock_print) -> None:
mock_print.assert_has_calls(expected_calls, any_order=False)

@patch("builtins.print")
def test_output_params_qgcs_SYSID_THISMAV(self, mock_print) -> None: # pylint: disable=invalid-name
def test_output_params_qgcs_SYSID_THISMAV(self, mock_print) -> None: # noqa: N802, pylint: disable=invalid-name
# Prepare a dummy defaults dictionary
defaults = {"PARAM2": 2.0, "PARAM1": 1.0, "SYSID_THISMAV": 3.0}

Expand All @@ -276,7 +276,7 @@ def test_output_params_qgcs_SYSID_THISMAV(self, mock_print) -> None: # pylint:
mock_print.assert_has_calls(expected_calls, any_order=False)

@patch("builtins.print")
def test_output_params_qgcs_SYSID_INVALID(self, _mock_print) -> None: # pylint: disable=invalid-name
def test_output_params_qgcs_SYSID_INVALID(self, _mock_print) -> None: # noqa: N802, pylint: disable=invalid-name
# Prepare a dummy defaults dictionary
defaults = {"PARAM2": 2.0, "PARAM1": 1.0, "SYSID_THISMAV": -1.0}

Expand All @@ -293,7 +293,7 @@ def test_output_params_qgcs_SYSID_INVALID(self, _mock_print) -> None: # pylint:
self.assertEqual(str(cm.exception), f"Invalid system ID parameter 16777218 must be smaller than {MAVLINK_SYSID_MAX}")

@patch("builtins.print")
def test_output_params_qgcs_COMPID_INVALID(self, _mock_print) -> None: # pylint: disable=invalid-name
def test_output_params_qgcs_COMPID_INVALID(self, _mock_print) -> None: # noqa: N802, pylint: disable=invalid-name
# Prepare a dummy defaults dictionary
defaults = {"PARAM2": 2.0, "PARAM1": 1.0}

Expand Down

0 comments on commit b85a9c3

Please sign in to comment.