Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] [pre-commit] Some pre-commit improvements
@ 2026-07-20 12:50 Tom de Vries
  2026-07-20 12:50 ` [PATCH 1/5] [gdb] Fix bare except in gdb/gdb-gdb.py.in Tom de Vries
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

This patch series contains some pre-commit improvements.

The third patch fixes the problem that flake8 is not run for gdb/gdb-gdb.py.in.

The first and second patch fix flake8 problems in gdb/gdb-gdb.py.in.

The fourth and fifth patch makes pre-commit rely less on types filtering,
fixing PR build/34411.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34411

Tom de Vries (5):
  [gdb] Fix bare except in gdb/gdb-gdb.py.in
  [gdb] Remove superfluous global in gdb/gdb-gdb.py.in
  [pre-commit] Run flake8 for gdb/gdb-gdb.py.in
  [pre-commit] Don't require text type for check-whitespace hook
  [pre-commit] Don't require text type for codespell hook

 .pre-commit-config.yaml      | 25 ++++++++++++++++++++-----
 gdb/doc/.gitattributes       | 10 ++++++++++
 gdb/gdb-gdb.py.in            |  3 +--
 gdb/testsuite/.gitattributes |  4 ++++
 4 files changed, 35 insertions(+), 7 deletions(-)
 create mode 100644 gdb/doc/.gitattributes
 create mode 100644 gdb/testsuite/.gitattributes


base-commit: cef1fbf3b02ff6e5bc62e1b8a7d30c0a32b8b9f7
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] [gdb] Fix bare except in gdb/gdb-gdb.py.in
  2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
@ 2026-07-20 12:50 ` Tom de Vries
  2026-07-20 12:50 ` [PATCH 2/5] [gdb] Remove superfluous global " Tom de Vries
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

Fix the following flake8 error:
...
gdb/gdb-gdb.py.in:97:9: E722 do not use bare 'except'
...

The problem is that bare except catches all exceptions, also SystemExit and
KeyboardInterrupt.

Fix this by using 'except Exception'.
---
 gdb/gdb-gdb.py.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 417b6492db5..8ed8169afa2 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -94,7 +94,7 @@ class TypeFlagsPrinter:
         TYPE_FLAGS = []
         try:
             iflags = gdb.lookup_type("enum type_instance_flag_value")
-        except:
+        except Exception:
             print("Warning: Cannot find enum type_instance_flag_value type.")
             print("         `struct type' pretty-printer will be degraded")
             return
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/5] [gdb] Remove superfluous global in gdb/gdb-gdb.py.in
  2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
  2026-07-20 12:50 ` [PATCH 1/5] [gdb] Fix bare except in gdb/gdb-gdb.py.in Tom de Vries
@ 2026-07-20 12:50 ` Tom de Vries
  2026-07-20 12:50 ` [PATCH 3/5] [pre-commit] Run flake8 for gdb/gdb-gdb.py.in Tom de Vries
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

Fix the following flake8 error:
...
gdb/gdb-gdb.py.in:71:9: F824 `global TYPE_FLAGS` is unused: \
  name is never assigned in scope
...
by removing the superfluous global statement.
---
 gdb/gdb-gdb.py.in | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 8ed8169afa2..e1db0a594bb 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -68,7 +68,6 @@ class TypeFlagsPrinter:
         self.val = val
 
     def __str__(self):
-        global TYPE_FLAGS
         if TYPE_FLAGS is None:
             self.init_TYPE_FLAGS()
         if not self.val:
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/5] [pre-commit] Run flake8 for gdb/gdb-gdb.py.in
  2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
  2026-07-20 12:50 ` [PATCH 1/5] [gdb] Fix bare except in gdb/gdb-gdb.py.in Tom de Vries
  2026-07-20 12:50 ` [PATCH 2/5] [gdb] Remove superfluous global " Tom de Vries
@ 2026-07-20 12:50 ` Tom de Vries
  2026-07-20 12:50 ` [PATCH 4/5] [pre-commit] Don't require text type for check-whitespace hook Tom de Vries
  2026-07-20 12:50 ` [PATCH 5/5] [pre-commit] Don't require text type for codespell hook Tom de Vries
  4 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

When running the pre-commit hooks for gdb/gdb-gdb.py.in:
...
$ pre-commit run --files gdb/gdb-gdb.py.in
black...................................................................Passed
flake8..............................................(no files to check)Skipped
isort...................................................................Passed
codespell...............................................................Passed
tclint..............................................(no files to check)Skipped
check-include-guards................................(no files to check)Skipped
check-gnu-style.....................................(no files to check)Skipped
- hook id: check-gnu-style
check-whitespace........................................................Passed
pre-commit-setup........................................................Passed
check-file-mode.........................................................Passed
...
we see that flake8 is skipped.

The hook setup has a types_or workaround that's supposed to prevent this:
...
    - id: flake8
      types_or: *gdb_python_types
      files: *gdb_python_files
      args: [--config, gdb/setup.cfg]
...
but that doesn't work because flake8's .pre-commit-hooks.yaml doesn't set
types_or, but types:
...
    types: [python]
...

So we end up with an effective setting of both types and types_or:
...
    types: [python]
    types_or: [file]
...
which both have to be matched, and because gdb/gdb-gdb.py.in doesn't match
python:
...
$ identify-cli gdb/gdb-gdb.py.in
["file", "non-executable", "text"]
...
the file is skipped.

This could be fixed by:
...
-    types_or: [file]
+    types: [file]
...
but an isort update setting types_or could reintroduce the same problem.

For robustness, fix this by setting both types and types_or for each python
hook.

Using the same value for both settings would work:
...
    types: [file]
    types_or: [file]
...
because types and types_or have the same effect for list lengths 0 and 1.

But I think it's better to have different anchors to avoid any confusion about
the and/or behavior, in which case it's more natural to use the actual default
[] for types_or, and to update the anchor names to reflect that these are the
default values:
...
    types: &types_default [file]
    types_or: &types_or_default []
...
---
 .pre-commit-config.yaml | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 60164e446fc..b437593b228 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -53,26 +53,33 @@ repos:
   #  - gdb/testsuite/*.py
   #
   # Because gdb/gdb-gdb.py.in is not classified as python, we use
-  # 'types_or: [file]' to override the default type for these hooks.
+  # 'types: [file] / types_or: []' to override the default settings for these
+  # hooks.
+  #
+  # To be robust we set both types and types_or for each hook.  Typically a
+  # repo sets only one of these, but that may change with any update.
   #
   - repo: https://github.com/psf/black-pre-commit-mirror
     rev: 26.5.1
     hooks:
     - id: black
-      types_or: &gdb_python_types [file]
+      types: &types_default [file]
+      types_or: &types_or_default []
       files: &gdb_python_files '^gdb/.*\.py(\.in)?$'
   - repo:  https://github.com/pycqa/flake8
     rev: 7.3.0
     hooks:
     - id: flake8
-      types_or: *gdb_python_types
+      types: *types_default
+      types_or: *types_or_default
       files: *gdb_python_files
       args: [--config, gdb/setup.cfg]
   - repo: https://github.com/pycqa/isort
     rev: 9.0.0b1
     hooks:
     - id: isort
-      types_or: *gdb_python_types
+      types: *types_default
+      types_or: *types_or_default
       files: *gdb_python_files
       # Isort's .pre-commit-hooks.yaml sets stages, overriding default_stages,
       # so this hook needs an explicit setting.
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/5] [pre-commit] Don't require text type for check-whitespace hook
  2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
                   ` (2 preceding siblings ...)
  2026-07-20 12:50 ` [PATCH 3/5] [pre-commit] Run flake8 for gdb/gdb-gdb.py.in Tom de Vries
@ 2026-07-20 12:50 ` Tom de Vries
  2026-07-20 12:50 ` [PATCH 5/5] [pre-commit] Don't require text type for codespell hook Tom de Vries
  4 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

The check-whitespace hook has a line:
...
types: ['text']
...

Drop this, to make the check-whitespace hook see the same files as git usage
outside pre-commit:
...
$ git diff-index --cached --check $(git hash-object -t tree /dev/null) gdb*
...

Instead, add .gitattributes files in gdb/doc and gdb/testsuite.

https://sourceware.org/bugzilla/show_bug.cgi?id=34411
---
 .pre-commit-config.yaml      |  5 ++++-
 gdb/doc/.gitattributes       | 10 ++++++++++
 gdb/testsuite/.gitattributes |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gdb/doc/.gitattributes
 create mode 100644 gdb/testsuite/.gitattributes

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b437593b228..260cae67e56 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -129,7 +129,10 @@ repos:
       name: *id2
       language: unsupported_script
       entry: gdb/contrib/check-whitespace-pre-commit.py
-      types: ['text']
+      # Don't filter files on types, allowing this hook to see same files as
+      # git usage outside pre-commit. Instead, filter files in the entry point.
+      types: *types_default
+      types_or: *types_or_default
       files: *gdb_files
     - id: &id3 pre-commit-setup
       name: *id3
diff --git a/gdb/doc/.gitattributes b/gdb/doc/.gitattributes
new file mode 100644
index 00000000000..735e4eef89a
--- /dev/null
+++ b/gdb/doc/.gitattributes
@@ -0,0 +1,10 @@
+# -*- conf -*-
+
+# Binary format.
+*.pdf  binary
+*.png  binary
+
+# Text format, but diffs aren't useful.
+# Note that stack_frame.eps is an EPS file without embedded bitmap preview.
+*.svg  text -diff
+stack_frame.eps  text -diff
diff --git a/gdb/testsuite/.gitattributes b/gdb/testsuite/.gitattributes
new file mode 100644
index 00000000000..97a376c1938
--- /dev/null
+++ b/gdb/testsuite/.gitattributes
@@ -0,0 +1,4 @@
+# -*- conf -*-
+
+# Binary format.
+*.bz2  binary
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/5] [pre-commit] Don't require text type for codespell hook
  2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
                   ` (3 preceding siblings ...)
  2026-07-20 12:50 ` [PATCH 4/5] [pre-commit] Don't require text type for check-whitespace hook Tom de Vries
@ 2026-07-20 12:50 ` Tom de Vries
  4 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2026-07-20 12:50 UTC (permalink / raw)
  To: gdb-patches

Codespell's .pre-commit-hooks.yaml sets "types: [text]".

Override this using "types: [file]", to make the codespell hook see the same
files as codespell usage outside pre-commit:
...
$ codespell --toml gdb/pyproject.toml gdb*
...

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34411
---
 .pre-commit-config.yaml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 260cae67e56..aeb3058f725 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -92,6 +92,11 @@ repos:
     - id: codespell
       args: &codespell_args [--toml, gdb/pyproject.toml]
       files: &gdb_files '^(gdb|gdbserver|gdbsupport)/'
+      # Override the [text] setting in .pre-commit-hooks.yaml, allowing this
+      # hook to see the same files as codespell usage outside pre-commit.
+      # Instead, filter files in gdb/pyproject.toml.
+      types: *types_default
+      types_or: *types_or_default
     - id: codespell
       name: codespell-log
       entry: gdb/contrib/codespell-log.sh
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-20 12:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20 12:50 [PATCH 0/5] [pre-commit] Some pre-commit improvements Tom de Vries
2026-07-20 12:50 ` [PATCH 1/5] [gdb] Fix bare except in gdb/gdb-gdb.py.in Tom de Vries
2026-07-20 12:50 ` [PATCH 2/5] [gdb] Remove superfluous global " Tom de Vries
2026-07-20 12:50 ` [PATCH 3/5] [pre-commit] Run flake8 for gdb/gdb-gdb.py.in Tom de Vries
2026-07-20 12:50 ` [PATCH 4/5] [pre-commit] Don't require text type for check-whitespace hook Tom de Vries
2026-07-20 12:50 ` [PATCH 5/5] [pre-commit] Don't require text type for codespell hook Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox