Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report file name of file that chardet fails to read #3524

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Commits on Aug 18, 2024

  1. feat: report file name of file that chardet fails to read

    resolves codespell-project#3519
    
    Tested and it works now, reporting the file name:
    
    ```
    codespell --write-changes -i3 -C 5 -H -f -e --count -s --builtin clear,rare,names
    Failed to decode file ./pep_sphinx_extensions/tests/pep_lint/test_pep_number.py using detected encoding Windows-1254.
    Traceback (most recent call last):
      File "/Users/corneliusromer/micromamba/envs/codespell/bin/codespell", line 8, in <module>
        sys.exit(_script_main())
                 ^^^^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 1103, in _script_main
        return main(*sys.argv[1:])
               ^^^^^^^^^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 1300, in main
        bad_count += parse_file(
                     ^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 945, in parse_file
        lines, encoding = file_opener.open(filename)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 232, in open
        return self.open_with_chardet(filename)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 246, in open_with_chardet
        lines = self.get_lines(f)
                ^^^^^^^^^^^^^^^^^
      File "/Users/corneliusromer/code/codespell/codespell_lib/_codespell.py", line 303, in get_lines
        lines = f.readlines()
                ^^^^^^^^^^^^^
      File "/Users/corneliusromer/micromamba/envs/codespell/lib/python3.12/encodings/cp1254.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 1349: character maps to <undefined>
    ```
    corneliusroemer committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    7c3df9c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6d27fef View commit details
    Browse the repository at this point in the history
  3. Alternative to address @DimitriPapadopoulos' concerns re too many cha…

    …nges.
    
    We require the type info, otherwise mypy fails
    corneliusroemer committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    f74ceda View commit details
    Browse the repository at this point in the history
  4. REduce diff size

    corneliusroemer committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    53ce7ea View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    283d0cd View commit details
    Browse the repository at this point in the history
  6. Cleaner formatting

    corneliusroemer committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    3159f71 View commit details
    Browse the repository at this point in the history
  7. Add tests

    corneliusroemer committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    c01a2bd View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    5209c5f View commit details
    Browse the repository at this point in the history