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: hooks:
- id: black - id: black
files: 'gui/.*\.py' 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 - repo: https://github.com/pycqa/isort
rev: 7.0.0 rev: 7.0.0
hooks: 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 # 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 # 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__)) self_dir = os.path.abspath(os.path.dirname(__file__))
# Import anything that defines a command or parameter. # Import anything that defines a command or parameter.
import gui.commands import gui.commands # noqa: E402
import gui.framecache import gui.framecache # noqa: E402
# Hooks in to gdb. # Hooks in to gdb.
import gui.notify import gui.notify # noqa: E402
import gui.params import gui.params # noqa: E402
import gui.toplevel 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 # 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 # 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) gui.adapt.notify_bug(18385)
try: try:
(rest, locs) = gdb.decode_line(bp.location) (rest, locs) = gdb.decode_line(bp.location)
except: except Exception:
return return
if rest is not None: if rest is not None:
# Let's assume we couldn't reparse for some reason. # 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 # 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 # it under the terms of the GNU General Public License as published by
@@ -325,7 +325,7 @@ class TestCommand(gdb.Command):
else: else:
try: try:
super(TestCommand, self).invoke(arg, from_tty) super(TestCommand, self).invoke(arg, from_tty)
except: except Exception:
pass 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 # 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 # it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ class DPrintfBreakpoint(gdb.Breakpoint):
try: try:
text = gdb.execute(self.command, False, True) text = gdb.execute(self.command, False, True)
except something: except Exception as something:
text = something text = something
window.append(text) 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 # 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 # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@ def check_frame():
sel = None sel = None
try: try:
sel = gdb.selected_frame() sel = gdb.selected_frame()
except: except Exception:
pass pass
if _last_selected_frame is not sel: if _last_selected_frame is not sel:
_last_selected_frame = 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 # 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 # 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... # GDB's API should do this...
def substitute_prompt_with_window(prompt, window): def substitute_prompt_with_window(prompt, window):
global _current_window_for_prompt global _current_window_for_prompt
global gui_prompt_substitutions
save = gdb.prompt.prompt_substitutions save = gdb.prompt.prompt_substitutions
_current_window_for_prompt = window _current_window_for_prompt = window
gdb.prompt.prompt_substitutions = gui_prompt_substitutions gdb.prompt.prompt_substitutions = gui_prompt_substitutions
@@ -56,7 +55,6 @@ def substitute_prompt_with_window(prompt, window):
# GDB's API should do this... # GDB's API should do this...
def prompt_help_with_window(window): def prompt_help_with_window(window):
global _current_window_for_prompt global _current_window_for_prompt
global gui_prompt_substitutions
save = gdb.prompt.prompt_substitutions save = gdb.prompt.prompt_substitutions
_current_window_for_prompt = window _current_window_for_prompt = window
gdb.prompt.prompt_substitutions = gui_prompt_substitutions 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 # 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 # it under the terms of the GNU General Public License as published by
@@ -87,7 +87,7 @@ class BufferManager:
buff.begin_not_undoable_action() buff.begin_not_undoable_action()
try: try:
contents = open(filename).read() contents = open(filename).read()
except: except Exception:
return None return None
buff.set_text(contents) buff.set_text(contents)
buff.end_not_undoable_action() 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 # 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 # it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@ import queue
import threading import threading
import gdb import gdb
import gi
from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, GtkSource from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, GtkSource
import gui import gui
@@ -37,14 +36,12 @@ def send_to_gtk(func):
class _GtkThread(gdb.Thread): class _GtkThread(gdb.Thread):
def handle_queue(self, source, condition): def handle_queue(self, source, condition):
global _event_queue
os.read(source, 1) os.read(source, 1)
func = _event_queue.get() func = _event_queue.get()
func() func()
return True return True
def run(self): def run(self):
global read_pipe
GObject.io_add_watch(read_pipe, GObject.IO_IN, self.handle_queue) GObject.io_add_watch(read_pipe, GObject.IO_IN, self.handle_queue)
GObject.type_register(GtkSource.View) GObject.type_register(GtkSource.View)
Gtk.main() 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