[Bug build/34291] New: [gdb/build] codespell warnings on iso-8859-1 encoded source files

"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=34291

            Bug ID: 34291
           Summary: [gdb/build] codespell warnings on iso-8859-1 encoded
                    source files
           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: ---

If we run the codespell pre-commit hook with -v, we get:
...
$ pre-commit run codespell --all-files -v
codespell................................................................Passed
- hook id: codespell
- duration: 1.52s

WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-1/pack.adb
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.python/py-source-styling.c
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-3/pack.ads
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-1/prog.adb
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-1/pack.ads
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-3/prog.adb
WARNING: Trying next encoding "iso-8859-1"
WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-3/pack.adb
WARNING: Trying next encoding "iso-8859-1"
...

The file are spell-checked, so that's not a problem:
...
$ echo "availabe" >> gdb/testsuite/gdb.ada/non-ascii-latin-1/pack.adb
$ git commit -a
  ...
codespell................................................................Failed
- hook id: codespell
- exit code: 65

WARNING: Cannot decode file using encoding "utf-8":
gdb/testsuite/gdb.ada/non-ascii-latin-1/pack.adb
WARNING: Trying next encoding "iso-8859-1"
gdb/testsuite/gdb.ada/non-ascii-latin-1/pack.adb:29: availabe ==> available
...

IWBN to get rid of the warnings.

I tried out:
...
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 351b9f6933f..63486a3946d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -73,6 +73,7 @@ repos:
     - id: codespell
       files: '^(gdb|gdbserver|gdbsupport)/'
       args: [--toml, gdb/pyproject.toml]
+      additional_dependencies: ["chardet"]
     - id: codespell
       name: codespell-log
       entry: gdb/contrib/codespell-log.sh
diff --git a/gdb/pyproject.toml b/gdb/pyproject.toml
index d6b3892ae4f..186b9bfca49 100644
--- a/gdb/pyproject.toml
+++ b/gdb/pyproject.toml
@@ -149,3 +149,5 @@ uri-ignore-words-list = '*'

 # How to ignore blocks of code.
 ignore-multiline-regex = 'codespell:ignore-begin.*?codespell:ignore-end'
+
+hard-encoding-detection = true
...
but that didn't help:
...
$ pre-commit run codespell --all-files -v
codespell................................................................Failed
- hook id: codespell
- duration: 2.67s
- exit code: 1

Traceback (most recent call last):
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/bin/codespell",
line 6, in <module>
    sys.exit(_script_main())
             ~~~~~~~~~~~~^^
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 1234, in _script_main
    return main(*sys.argv[1:])
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 1460, in main
    bad_count += parse_file(
                 ~~~~~~~~~~^
        filename,
        ^^^^^^^^^
    ...<11 lines>...
        options,
        ^^^^^^^^
    )
    ^
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 1158, in parse_file
    fragments, encoding = file_opener.open(filename)
                          ~~~~~~~~~~~~~~~~^^^^^^^^^^
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 243, in open
    return self.open_with_chardet(filename)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 270, in open_with_chardet
    lines = self.get_lines(f)
  File
"/home/vries/.cache/pre-commit/repoirc22v9a/py_env-python3.13/lib/python3.13/site-packages/codespell_lib/_codespell.py",
line 308, in get_lines
    text = f.read()
  File "<frozen codecs>", line 325, in decode
UnicodeDecodeError: 'utf7' codec can't decode bytes in position 5593-5596:
partial character in shift sequence
...

Perhaps this needs fixing in codespell.

-- 
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.