* [PATCH] [pre-commit] Remove duplication in config file
@ 2026-06-18 7:47 Tom de Vries
2026-07-13 11:14 ` Tom de Vries
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-06-18 7:47 UTC (permalink / raw)
To: gdb-patches
In a recent commit, I introduced anchor/alias pairs in
.pre-commit-config.yaml, with short non-descriptive names for local use:
...
- - id: check-include-guards
- name: check-include-guards
+ - id: &id0 check-include-guards
+ name: *id0
...
Use anchor and aliases a bit more to remove duplication, now using more
descriptive names for non-local uses.
Yaml also supports defining an anchor for more than one field, which result in
cleaner code:
...
+python-files: &python-files
+ types_or: [file]
+ files: '^gdb/.*\.py(\.in)?$'
+
...
- id: black
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ <<: *python-files
...
but unfortunately pre-commit generates a warning "[WARNING] Unexpected key(s)
present at root: python-files" for this [1].
Also add a default files setting.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34295
[1] https://github.com/pre-commit/pre-commit/issues/1481
---
.pre-commit-config.yaml | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 141451501ed..c15a1c64690 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -40,6 +40,7 @@
minimum_pre_commit_version: 4.5.1
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [pre-commit]
+files: '^(gdb|gdbserver|gdbsupport)/'
repos:
# Python hooks. Run these for (in glob notation):
@@ -56,33 +57,32 @@ repos:
rev: 26.5.1
hooks:
- id: black
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: &gdb_python_types [file]
+ files: &gdb_python_files '^gdb/.*\.py(\.in)?$'
- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: *gdb_python_types
+ files: *gdb_python_files
args: [--config, gdb/setup.cfg]
- repo: https://github.com/pycqa/isort
rev: 9.0.0a3
hooks:
- id: isort
- types_or: [file]
- files: '^gdb/.*\.py(\.in)?$'
+ types_or: *gdb_python_types
+ files: *gdb_python_files
# Codespell hooks.
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
hooks:
- id: codespell
- files: '^(gdb|gdbserver|gdbsupport)/'
- args: [--toml, gdb/pyproject.toml]
+ args: &codespell_args [--toml, gdb/pyproject.toml]
- id: codespell
name: codespell-log
entry: gdb/contrib/codespell-log.sh
- args: [--toml, gdb/pyproject.toml]
+ args: *codespell_args
verbose: true
stages: [commit-msg]
@@ -116,7 +116,6 @@ repos:
name: *id2
language: unsupported_script
entry: gdb/contrib/check-whitespace-pre-commit.py
- files: '^(gdb(support|server)?)/.*$'
- id: &id3 pre-commit-setup
name: *id3
language: python
@@ -128,4 +127,3 @@ repos:
name: *id4
language: unsupported_script
entry: gdb/contrib/check-file-mode.sh
- files: '^(gdb|gdbserver|gdbsupport)/.*$'
base-commit: 0c6ebc781ac79cd64d12d8acc1cb50fd4de2bb3a
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [pre-commit] Remove duplication in config file
2026-06-18 7:47 [PATCH] [pre-commit] Remove duplication in config file Tom de Vries
@ 2026-07-13 11:14 ` Tom de Vries
0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2026-07-13 11:14 UTC (permalink / raw)
To: gdb-patches
On 6/18/26 9:47 AM, Tom de Vries wrote:
> In a recent commit, I introduced anchor/alias pairs in
> .pre-commit-config.yaml, with short non-descriptive names for local use:
> ...
> - - id: check-include-guards
> - name: check-include-guards
> + - id: &id0 check-include-guards
> + name: *id0
> ...
>
> Use anchor and aliases a bit more to remove duplication, now using more
> descriptive names for non-local uses.
>
> Yaml also supports defining an anchor for more than one field, which result in
> cleaner code:
> ...
> +python-files: &python-files
> + types_or: [file]
> + files: '^gdb/.*\.py(\.in)?$'
> +
> ...
> - id: black
> - types_or: [file]
> - files: '^gdb/.*\.py(\.in)?$'
> + <<: *python-files
> ...
> but unfortunately pre-commit generates a warning "[WARNING] Unexpected key(s)
> present at root: python-files" for this [1].
>
> Also add a default files setting.
>
I've pushed this.
Thanks,
- Tom
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34295
>
> [1] https://github.com/pre-commit/pre-commit/issues/1481
> ---
> .pre-commit-config.yaml | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
> index 141451501ed..c15a1c64690 100644
> --- a/.pre-commit-config.yaml
> +++ b/.pre-commit-config.yaml
> @@ -40,6 +40,7 @@
> minimum_pre_commit_version: 4.5.1
> default_install_hook_types: [pre-commit, commit-msg]
> default_stages: [pre-commit]
> +files: '^(gdb|gdbserver|gdbsupport)/'
>
> repos:
> # Python hooks. Run these for (in glob notation):
> @@ -56,33 +57,32 @@ repos:
> rev: 26.5.1
> hooks:
> - id: black
> - types_or: [file]
> - files: '^gdb/.*\.py(\.in)?$'
> + types_or: &gdb_python_types [file]
> + files: &gdb_python_files '^gdb/.*\.py(\.in)?$'
> - repo: https://github.com/pycqa/flake8
> rev: 7.3.0
> hooks:
> - id: flake8
> - types_or: [file]
> - files: '^gdb/.*\.py(\.in)?$'
> + types_or: *gdb_python_types
> + files: *gdb_python_files
> args: [--config, gdb/setup.cfg]
> - repo: https://github.com/pycqa/isort
> rev: 9.0.0a3
> hooks:
> - id: isort
> - types_or: [file]
> - files: '^gdb/.*\.py(\.in)?$'
> + types_or: *gdb_python_types
> + files: *gdb_python_files
>
> # Codespell hooks.
> - repo: https://github.com/codespell-project/codespell
> rev: v2.4.2
> hooks:
> - id: codespell
> - files: '^(gdb|gdbserver|gdbsupport)/'
> - args: [--toml, gdb/pyproject.toml]
> + args: &codespell_args [--toml, gdb/pyproject.toml]
> - id: codespell
> name: codespell-log
> entry: gdb/contrib/codespell-log.sh
> - args: [--toml, gdb/pyproject.toml]
> + args: *codespell_args
> verbose: true
> stages: [commit-msg]
>
> @@ -116,7 +116,6 @@ repos:
> name: *id2
> language: unsupported_script
> entry: gdb/contrib/check-whitespace-pre-commit.py
> - files: '^(gdb(support|server)?)/.*$'
> - id: &id3 pre-commit-setup
> name: *id3
> language: python
> @@ -128,4 +127,3 @@ repos:
> name: *id4
> language: unsupported_script
> entry: gdb/contrib/check-file-mode.sh
> - files: '^(gdb|gdbserver|gdbsupport)/.*$'
>
> base-commit: 0c6ebc781ac79cd64d12d8acc1cb50fd4de2bb3a
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-13 11:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-18 7:47 [PATCH] [pre-commit] Remove duplication in config file Tom de Vries
2026-07-13 11:14 ` 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