Skip to content

Commit c2b8bda

Browse files
committed
FIX: enforce ruff rule FBT003
1 parent 7b74afd commit c2b8bda

9 files changed

+68
-63
lines changed

MethodicConfigurator/backend_filesystem_program_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def valid_directory_name(dir_name: str) -> bool:
9292

9393
@staticmethod
9494
def __user_config_dir() -> str:
95-
user_config_directory = user_config_dir(".ardupilot_methodic_configurator", False, roaming=True, ensure_exists=True)
95+
user_config_directory = user_config_dir(
96+
".ardupilot_methodic_configurator", appauthor=False, roaming=True, ensure_exists=True
97+
)
9698

9799
if not os_path.exists(user_config_directory):
98100
error_msg = _("The user configuration directory '{user_config_directory}' does not exist.")
@@ -106,7 +108,7 @@ def __user_config_dir() -> str:
106108
@staticmethod
107109
def __site_config_dir() -> str:
108110
site_config_directory = site_config_dir(
109-
".ardupilot_methodic_configurator", False, version=None, multipath=False, ensure_exists=True
111+
".ardupilot_methodic_configurator", appauthor=False, version=None, multipath=False, ensure_exists=True
110112
)
111113

112114
if not os_path.exists(site_config_directory):

MethodicConfigurator/frontend_tkinter_base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def leave(_event: tk.Event) -> None:
6464
tooltip.withdraw()
6565

6666
tooltip = tk.Toplevel(widget)
67-
tooltip.wm_overrideredirect(True)
67+
tooltip.wm_overrideredirect(boolean=True)
6868
tooltip_label = ttk.Label(tooltip, text=text, background="#ffffe0", relief="solid", borderwidth=1, justify=tk.LEFT)
6969
tooltip_label.pack()
7070
tooltip.withdraw() # Initially hide the tooltip
@@ -351,7 +351,7 @@ def __init__(self, root_tk: Optional[tk.Toplevel] = None) -> None:
351351
self.root = tk.Tk() # type: ignore[assignment]
352352
# Set the application icon for the window and all child windows
353353
# https://pythonassets.com/posts/window-icon-in-tk-tkinter/
354-
self.root.iconphoto(True, tk.PhotoImage(file=LocalFilesystem.application_icon_filepath()))
354+
self.root.iconphoto(True, tk.PhotoImage(file=LocalFilesystem.application_icon_filepath())) # noqa: FBT003
355355

356356
# Set the theme to 'alt'
357357
style = ttk.Style()
@@ -450,16 +450,16 @@ def update_show_again() -> None:
450450
dismiss_button.pack(pady=10)
451451

452452
BaseWindow.center_window(usage_popup_window.root, parent)
453-
usage_popup_window.root.attributes("-topmost", True)
453+
usage_popup_window.root.attributes("-topmost", True) # noqa: FBT003
454454

455455
if platform_system() == "Windows":
456-
parent.attributes("-disabled", True) # Disable parent window input
456+
parent.attributes("-disabled", True) # noqa: FBT003 # Disable parent window input
457457

458458
usage_popup_window.root.protocol("WM_DELETE_WINDOW", lambda: UsagePopupWindow.close(usage_popup_window, parent))
459459

460460
@staticmethod
461461
def close(usage_popup_window: BaseWindow, parent: tk.Toplevel) -> None:
462462
usage_popup_window.root.destroy()
463463
if platform_system() == "Windows":
464-
parent.attributes("-disabled", False) # Re-enable the parent window
464+
parent.attributes("-disabled", False) # noqa: FBT003 # Re-enable the parent window
465465
parent.focus_set()

MethodicConfigurator/frontend_tkinter_directory_selection.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen
157157
) -> None:
158158
# Call the parent constructor with the necessary arguments
159159
super().__init__(
160-
parent,
161-
parent_frame,
162-
initial_dir,
163-
_("Vehicle configuration directory:"),
164-
False,
165-
_(
160+
parent=parent,
161+
parent_frame=parent_frame,
162+
initialdir=initial_dir,
163+
label_text=_("Vehicle configuration directory:"),
164+
autoresize_width=False,
165+
dir_tooltip=_(
166166
"Vehicle-specific directory containing the intermediate\n"
167167
"parameter files to be uploaded to the flight controller"
168168
),
169-
_(
169+
button_tooltip=_(
170170
"Select the vehicle-specific configuration directory containing the\n"
171171
"intermediate parameter files to be uploaded to the flight controller"
172172
)
173173
if destroy_parent_on_open
174174
else "",
175-
False,
175+
is_template_selection=False,
176176
)
177177
self.local_filesystem = local_filesystem
178178
self.destroy_parent_on_open = destroy_parent_on_open
@@ -278,17 +278,16 @@ def create_option1_widgets(
278278
"parameter files to be copied to the new vehicle configuration directory"
279279
)
280280
self.template_dir = DirectorySelectionWidgets(
281-
self,
282-
option1_label_frame,
283-
initial_template_dir,
284-
_("Source Template directory:"),
285-
False,
286-
template_dir_edit_tooltip,
287-
template_dir_btn_tooltip,
288-
True,
281+
parent=self,
282+
parent_frame=option1_label_frame,
283+
initialdir=initial_template_dir,
284+
label_text=_("Source Template directory:"),
285+
autoresize_width=False,
286+
dir_tooltip=template_dir_edit_tooltip,
287+
button_tooltip=template_dir_btn_tooltip,
288+
is_template_selection=True,
289289
)
290290
self.template_dir.container_frame.pack(expand=False, fill=tk.X, padx=3, pady=5, anchor=tk.NW)
291-
292291
use_fc_params_checkbox = ttk.Checkbutton(
293292
option1_label_frame,
294293
variable=self.use_fc_params,
@@ -310,14 +309,14 @@ def create_option1_widgets(
310309
new_base_dir_edit_tooltip = _("Existing directory where the new vehicle configuration directory will be created")
311310
new_base_dir_btn_tooltip = _("Select the directory where the new vehicle configuration directory will be created")
312311
self.new_base_dir = DirectorySelectionWidgets(
313-
self,
314-
option1_label_frame,
315-
initial_base_dir,
316-
_("Destination base directory:"),
317-
False,
318-
new_base_dir_edit_tooltip,
319-
new_base_dir_btn_tooltip,
320-
False,
312+
parent=self,
313+
parent_frame=option1_label_frame,
314+
initialdir=initial_base_dir,
315+
label_text=_("Destination base directory:"),
316+
autoresize_width=False,
317+
dir_tooltip=new_base_dir_edit_tooltip,
318+
button_tooltip=new_base_dir_btn_tooltip,
319+
is_template_selection=False,
321320
)
322321
self.new_base_dir.container_frame.pack(expand=False, fill=tk.X, padx=3, pady=5, anchor=tk.NW)
323322
new_dir_edit_tooltip = _(
@@ -369,14 +368,14 @@ def create_option3_widgets(self, last_vehicle_dir: str) -> None:
369368
option3_label_frame.pack(expand=True, fill=tk.X, padx=6, pady=6)
370369

371370
last_dir = DirectorySelectionWidgets(
372-
self,
373-
option3_label_frame,
374-
last_vehicle_dir or "",
375-
_("Last used vehicle configuration directory:"),
376-
False,
377-
_("Last used vehicle configuration directory"),
378-
"",
379-
False,
371+
parent=self,
372+
parent_frame=option3_label_frame,
373+
initialdir=last_vehicle_dir or "",
374+
label_text=_("Last used vehicle configuration directory:"),
375+
autoresize_width=False,
376+
dir_tooltip=_("Last used vehicle configuration directory"),
377+
button_tooltip="",
378+
is_template_selection=False,
380379
)
381380
last_dir.container_frame.pack(expand=False, fill=tk.X, padx=3, pady=5, anchor=tk.NW)
382381

MethodicConfigurator/frontend_tkinter_pair_tuple_combobox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def create_tooltip(self, text: str) -> None:
186186
try:
187187
if self.tooltip is None or self.tooltip.winfo_exists():
188188
self.tooltip = Toplevel(self.master)
189-
self.tooltip.wm_overrideredirect(True)
189+
self.tooltip.wm_overrideredirect(boolean=True)
190190
x = self.winfo_rootx() + 150 # Adjust width as needed
191191
y = self.winfo_rooty()
192192
self.tooltip.wm_geometry(f"+{x}+{y}")

MethodicConfigurator/frontend_tkinter_parameter_editor.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def __init__(self, current_file: str, flight_controller: FlightController, local
174174
self.__create_parameter_area_widgets()
175175

176176
# trigger a table update to ask the user what to do in the case this file needs special actions
177-
self.root.after(10, self.on_param_file_combobox_change(None, True)) # type: ignore[func-returns-value]
177+
self.root.after(10, self.on_param_file_combobox_change(None, forced=True)) # type: ignore[func-returns-value]
178178

179179
# this one should be on top of the previous one hence the longer time
180180
if UsagePopupWindow.should_display("parameter_editor"):
@@ -409,14 +409,14 @@ def __do_tempcal_imu(self, selected_file: str) -> None:
409409
)
410410
# Pass the selected filename to the IMUfit class
411411
IMUfit(
412-
filename,
413-
tempcal_imu_result_param_fullpath,
414-
False,
415-
False,
416-
False,
417-
False,
418-
self.local_filesystem.vehicle_dir,
419-
self.tempcal_imu_progress_window.update_progress_bar_300_pct,
412+
logfile=filename,
413+
outfile=tempcal_imu_result_param_fullpath,
414+
no_graph=False,
415+
log_parm=False,
416+
online=False,
417+
tclr=False,
418+
figpath=self.local_filesystem.vehicle_dir,
419+
progress_callback=self.tempcal_imu_progress_window.update_progress_bar_300_pct,
420420
)
421421
self.tempcal_imu_progress_window.destroy()
422422
try:
@@ -520,7 +520,7 @@ def download_flight_controller_parameters(self, redownload: bool = False) -> Non
520520
self.local_filesystem.write_param_default_values_to_file(param_default_values)
521521
self.param_download_progress_window.destroy() # for the case that '--device test' and there is no real FC connected
522522
if not redownload:
523-
self.on_param_file_combobox_change(None, True) # the initial param read will trigger a table update
523+
self.on_param_file_combobox_change(None, forced=True) # the initial param read will trigger a table update
524524

525525
def repopulate_parameter_table(self, selected_file: Union[None, str]) -> None:
526526
if not selected_file:
@@ -650,7 +650,7 @@ def upload_selected_params(self, selected_params: dict) -> None:
650650

651651
if self.at_least_one_changed_parameter_written:
652652
# Re-download all parameters, in case one of them changed, and validate that all uploads were successful
653-
self.download_flight_controller_parameters(True)
653+
self.download_flight_controller_parameters(redownload=True)
654654
logging_info(_("Re-download all parameters from the flight controller"))
655655

656656
# Validate that the read parameters are the same as the ones in the current_file
@@ -756,13 +756,15 @@ def write_summary_files(self) -> None: # pylint: disable=too-many-locals
756756
"these can be reused between similar vehicles"
757757
)
758758
messagebox.showinfo(_("Last parameter file processed"), summary_message.format(**locals()))
759-
wrote_complete = self.write_summary_file(annotated_fc_parameters, "complete.param", False)
760-
wrote_read_only = self.write_summary_file(non_default__read_only_params, "non-default_read-only.param", False)
759+
wrote_complete = self.write_summary_file(annotated_fc_parameters, "complete.param", annotate_doc=False)
760+
wrote_read_only = self.write_summary_file(
761+
non_default__read_only_params, "non-default_read-only.param", annotate_doc=False
762+
)
761763
wrote_calibrations = self.write_summary_file(
762-
non_default__writable_calibrations, "non-default_writable_calibrations.param", False
764+
non_default__writable_calibrations, "non-default_writable_calibrations.param", annotate_doc=False
763765
)
764766
wrote_non_calibrations = self.write_summary_file(
765-
non_default__writable_non_calibrations, "non-default_writable_non-calibrations.param", False
767+
non_default__writable_non_calibrations, "non-default_writable_non-calibrations.param", annotate_doc=False
766768
)
767769
files_to_zip = [
768770
(wrote_complete, "complete.param"),

MethodicConfigurator/frontend_tkinter_parameter_editor_documentation_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def update_documentation_labels(self, current_file: str) -> None:
114114
)
115115
self.__update_documentation_label(_("External tool:"), external_tool_text, external_tool_url)
116116
mandatory_text, mandatory_url = self.local_filesystem.get_documentation_text_and_url(current_file, "mandatory")
117-
self.__update_documentation_label(_("Mandatory:"), mandatory_text, mandatory_url, False)
117+
self.__update_documentation_label(_("Mandatory:"), mandatory_text, mandatory_url, url_expected=False)
118118

119119
if self.auto_open_var.get():
120120
if wiki_url:

MethodicConfigurator/frontend_tkinter_template_overview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, parent: Optional[tk.Toplevel] = None) -> None:
105105
self.tree.heading(
106106
col_str,
107107
text=col_str,
108-
command=lambda col=col_str: self.__sort_by_column(col, False), # type: ignore[misc]
108+
command=lambda col=col_str: self.__sort_by_column(col, reverse=False), # type: ignore[misc]
109109
)
110110

111111
if isinstance(self.root, tk.Toplevel):

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ lint.select = [
100100
"ASYNC",# flake8-async
101101
"S", # flake8-bandit
102102
#"BLE", # flake8-blind-except
103-
#"FBT", # flake8-boolean-trap
103+
"FBT", # flake8-boolean-trap
104104
"B", # flake8-bugbear
105105
"A", # flake8-builtins
106106
"COM", # flake8-commas
@@ -165,6 +165,8 @@ lint.ignore = [
165165
"D401", # First line of docstring should be in imperative mood
166166
"COM812",
167167
"DTZ005", # `tz=None` passed to `datetime.datetime.now()`
168+
"FBT001", # Boolean-typed positional argument in function definition
169+
"FBT002", # Boolean default positional argument in function definition
168170
]
169171

170172
line-length = 127

unittests/backend_filesystem_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_read_params_from_files(self, mock_listdir, mock_isdir) -> None:
3232
LocalFilesystem.load_param_file_into_dict = mock_load_param_file_into_dict
3333

3434
# Call the method under test
35-
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, False)
35+
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, allow_editing_template_files=False)
3636
result = lfs.read_params_from_files()
3737

3838
# Assertions
@@ -42,7 +42,7 @@ def test_read_params_from_files(self, mock_listdir, mock_isdir) -> None:
4242
mock_load_param_file_into_dict.assert_called_once_with("vehicle_dir/02_test.param")
4343

4444
def test_str_to_bool(self) -> None:
45-
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, False)
45+
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, allow_editing_template_files=False)
4646
self.assertTrue(lfs.str_to_bool("true"))
4747
self.assertTrue(lfs.str_to_bool("yes"))
4848
self.assertTrue(lfs.str_to_bool("1"))
@@ -59,7 +59,7 @@ def test_re_init(self, mock_read_params_from_files, mock_listdir, mock_isdir) ->
5959
mock_listdir.return_value = ["00_default.param", "01_ignore_readonly.param", "02_test.param"]
6060
mock_read_params_from_files.return_value = {"02_test.param": {"TEST_PARAM": "value"}}
6161

62-
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, False)
62+
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, allow_editing_template_files=False)
6363
lfs.re_init("new_vehicle_dir", "new_vehicle_type")
6464

6565
self.assertEqual(lfs.vehicle_dir, "new_vehicle_dir")
@@ -97,7 +97,7 @@ def test_copy_template_files_to_new_vehicle_dir(self, mock_copy2, mock_copytree,
9797
mock_join.side_effect = lambda *args: "/".join(args)
9898

9999
# Initialize LocalFilesystem
100-
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, False)
100+
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, allow_editing_template_files=False)
101101

102102
# Call the method under test
103103
lfs.copy_template_files_to_new_vehicle_dir("template_dir", "new_vehicle_dir")

0 commit comments

Comments
 (0)