diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a02bf14..1141bbc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,13 @@ repos: hooks: - id: black files: 'gui/.*\.py' + - repo: https://github.com/pycqa/flake8 + rev: 7.3.0 + hooks: + - id: flake8 + types_or: [file] + files: '^gui/.*\.py' + args: [--config, setup.cfg] - repo: https://github.com/pycqa/isort rev: 7.0.0 hooks: diff --git a/gui/__init__.py b/gui/__init__.py index bc13186..5d77de2 100644 --- a/gui/__init__.py +++ b/gui/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013, 2015, 2024 Tom Tromey +# Copyright (C) 2013, 2015, 2024, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,10 +24,10 @@ gi.require_version("Notify", "0.7") self_dir = os.path.abspath(os.path.dirname(__file__)) # Import anything that defines a command or parameter. -import gui.commands -import gui.framecache +import gui.commands # noqa: E402 +import gui.framecache # noqa: E402 # Hooks in to gdb. -import gui.notify -import gui.params -import gui.toplevel +import gui.notify # noqa: E402 +import gui.params # noqa: E402 +import gui.toplevel # noqa: E402, F401 diff --git a/gui/bpcache.py b/gui/bpcache.py index 6518003..8c72414 100644 --- a/gui/bpcache.py +++ b/gui/bpcache.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015 Tom Tromey +# Copyright (C) 2015, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ def _breakpoint_created(bp): gui.adapt.notify_bug(18385) try: (rest, locs) = gdb.decode_line(bp.location) - except: + except Exception: return if rest is not None: # Let's assume we couldn't reparse for some reason. diff --git a/gui/commands.py b/gui/commands.py index 6fd24db..fec0936 100644 --- a/gui/commands.py +++ b/gui/commands.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012, 2013, 2015, 2016, 2023 Tom Tromey +# Copyright (C) 2012, 2013, 2015, 2016, 2023, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -325,7 +325,7 @@ class TestCommand(gdb.Command): else: try: super(TestCommand, self).invoke(arg, from_tty) - except: + except Exception: pass diff --git a/gui/dprintf.py b/gui/dprintf.py index 5cd7e89..d9fc583 100644 --- a/gui/dprintf.py +++ b/gui/dprintf.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Tom Tromey +# Copyright (C) 2013, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,7 +42,7 @@ class DPrintfBreakpoint(gdb.Breakpoint): try: text = gdb.execute(self.command, False, True) - except something: + except Exception as something: text = something window.append(text) diff --git a/gui/framecache.py b/gui/framecache.py index f2ddb4f..6b07bb6 100644 --- a/gui/framecache.py +++ b/gui/framecache.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015 Tom Tromey +# Copyright (C) 2015, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ def check_frame(): sel = None try: sel = gdb.selected_frame() - except: + except Exception: pass if _last_selected_frame is not sel: _last_selected_frame = sel diff --git a/gui/gdbutil.py b/gui/gdbutil.py index 09a7f81..a791938 100644 --- a/gui/gdbutil.py +++ b/gui/gdbutil.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015, 2023 Tom Tromey +# Copyright (C) 2015, 2023, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -41,7 +41,6 @@ gui_prompt_substitutions["W"] = _prompt_window # GDB's API should do this... def substitute_prompt_with_window(prompt, window): global _current_window_for_prompt - global gui_prompt_substitutions save = gdb.prompt.prompt_substitutions _current_window_for_prompt = window gdb.prompt.prompt_substitutions = gui_prompt_substitutions @@ -56,7 +55,6 @@ def substitute_prompt_with_window(prompt, window): # GDB's API should do this... def prompt_help_with_window(window): global _current_window_for_prompt - global gui_prompt_substitutions save = gdb.prompt.prompt_substitutions _current_window_for_prompt = window gdb.prompt.prompt_substitutions = gui_prompt_substitutions diff --git a/gui/source.py b/gui/source.py index 9d05c25..f53377f 100644 --- a/gui/source.py +++ b/gui/source.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012, 2013, 2015, 2023, 2024 Tom Tromey +# Copyright (C) 2012, 2013, 2015, 2023, 2024, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -87,7 +87,7 @@ class BufferManager: buff.begin_not_undoable_action() try: contents = open(filename).read() - except: + except Exception: return None buff.set_text(contents) buff.end_not_undoable_action() diff --git a/gui/startup.py b/gui/startup.py index 2041b43..1c9739b 100644 --- a/gui/startup.py +++ b/gui/startup.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012, 2013, 2015, 2023, 2024 Tom Tromey +# Copyright (C) 2012, 2013, 2015, 2023, 2024, 2025 Tom Tromey # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ import queue import threading import gdb -import gi from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, GtkSource import gui @@ -37,14 +36,12 @@ def send_to_gtk(func): class _GtkThread(gdb.Thread): def handle_queue(self, source, condition): - global _event_queue os.read(source, 1) func = _event_queue.get() func() return True def run(self): - global read_pipe GObject.io_add_watch(read_pipe, GObject.IO_IN, self.handle_queue) GObject.type_register(GtkSource.View) Gtk.main() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2e83eb5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,9 @@ +[flake8] +# Disable some formatted-related warnings that conflict with black's way of +# formatting code. +# +# E203: Whitespace before ':' +# E501: line too long +# E701: Multiple statements on one line (colon) +# W503: line break before binary operator +ignore = E203,E501,E701,W503