[PATCH 3/5] [pre-commit] Run flake8 for gdb/gdb-gdb.py.in
Tom de Vries <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
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