[Bug build/34295] New: [gdb/build] Make pre-commit config file more maintainable

"vries at gcc dot gnu.org via Gdb-prs" <[email protected]>
Newsgroups gmane.comp.gdb.bugs.discuss
Message-ID <[email protected]/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=34295

            Bug ID: 34295
           Summary: [gdb/build] Make pre-commit config file more
                    maintainable
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

I learned about yaml anchors and aliases, and tried it out in
.pre-commit-config.yaml.

I came up with:
...
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a5b526b1eec..16f6c60d7e0 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -37,6 +37,10 @@
 # See https://pre-commit.com for more information
 # See https://pre-commit.com/hooks.html for more hooks

+python-files: &python-files
+  types_or: [file]
+  files: '^gdb/.*\.py(\.in)?$'
+
 minimum_pre_commit_version: 4.5.1
 default_install_hook_types: [pre-commit, commit-msg]
 default_stages: [pre-commit]
@@ -45,13 +49,11 @@ repos:
     rev: 26.5.1
     hooks:
       - id: black
-        types_or: [file]
-        files: '^gdb/.*\.py(\.in)?$'
+        <<: *python-files
   - repo:  https://github.com/pycqa/flake8
     rev: 7.3.0
     hooks:
     - id: flake8
-      types_or: [file]
       # Run this for (in glob notation):
       #
       #  - gdb/gdb-gdb.py.in
@@ -59,14 +61,13 @@ repos:
       #  - gdb/python/**/*.py
       #  - gdb/testsuite/*.py
       #
-      files: '^gdb/.*\.py(\.in)?$'
+      <<: *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)?$'
+      <<: *python-files
   - repo: https://github.com/codespell-project/codespell
     rev: v2.4.2
     hooks:
...
which is a nice cleanup, but pre-commit does:
...
[WARNING] Unexpected key(s) present at root: python-files
...

This was discussed upstream (
https://github.com/pre-commit/pre-commit/issues/1481 ), but not resolved.

An idea would be to file another issue, with this use-case, which is slightly
different, and might persuade upstream to acknowledge the problem.

Another option would be to generate the file, but for now that's probably
overkill.

Another option is to use two anchors instead of one:
...
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a5b526b1eec..1c510c2347a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -45,13 +45,13 @@ repos:
     rev: 26.5.1
     hooks:
       - id: black
-        types_or: [file]
-        files: '^gdb/.*\.py(\.in)?$'
+        types_or: &python_file_types [file]
+        files: &python_file_names '^gdb/.*\.py(\.in)?$'
   - repo:  https://github.com/pycqa/flake8
     rev: 7.3.0
     hooks:
     - id: flake8
-      types_or: [file]
+      types_or: *python_file_types
       # Run this for (in glob notation):
       #
       #  - gdb/gdb-gdb.py.in
@@ -59,14 +59,14 @@ repos:
       #  - gdb/python/**/*.py
       #  - gdb/testsuite/*.py
       #
-      files: '^gdb/.*\.py(\.in)?$'
+      files: *python_file_names
       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: *python_file_types
+      files: *python_file_names
   - repo: https://github.com/codespell-project/codespell
     rev: v2.4.2
     hooks:
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.