add flake8

This commit is contained in:
Tom Tromey
2025-12-06 13:18:16 -06:00
parent dc5ea348e6
commit 48b2b25526
10 changed files with 34 additions and 23 deletions

View File

@@ -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:

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2013, 2015, 2024 Tom Tromey <tom@tromey.com>
# Copyright (C) 2013, 2015, 2024, 2025 Tom Tromey <tom@tromey.com>
# 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

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2015 Tom Tromey <tom@tromey.com>
# Copyright (C) 2015, 2025 Tom Tromey <tom@tromey.com>
# 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.

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2012, 2013, 2015, 2016, 2023 Tom Tromey <tom@tromey.com>
# Copyright (C) 2012, 2013, 2015, 2016, 2023, 2025 Tom Tromey <tom@tromey.com>
# 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

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2013 Tom Tromey <tom@tromey.com>
# Copyright (C) 2013, 2025 Tom Tromey <tom@tromey.com>
# 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)

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2015 Tom Tromey <tom@tromey.com>
# Copyright (C) 2015, 2025 Tom Tromey <tom@tromey.com>
# 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

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2015, 2023 Tom Tromey <tom@tromey.com>
# Copyright (C) 2015, 2023, 2025 Tom Tromey <tom@tromey.com>
# 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

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2012, 2013, 2015, 2023, 2024 Tom Tromey <tom@tromey.com>
# Copyright (C) 2012, 2013, 2015, 2023, 2024, 2025 Tom Tromey <tom@tromey.com>
# 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()

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2012, 2013, 2015, 2023, 2024 Tom Tromey <tom@tromey.com>
# Copyright (C) 2012, 2013, 2015, 2023, 2024, 2025 Tom Tromey <tom@tromey.com>
# 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()

9
setup.cfg Normal file
View File

@@ -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