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

UnicodeDecodeError when running pre-commit on Windows with v2.3.0 #294

Closed
sgbaird opened this issue Mar 12, 2024 · 1 comment · Fixed by #296
Closed

UnicodeDecodeError when running pre-commit on Windows with v2.3.0 #294

sgbaird opened this issue Mar 12, 2024 · 1 comment · Fixed by #296
Labels

Comments

@sgbaird
Copy link

sgbaird commented Mar 12, 2024

autoflake................................................................Failed
- hook id: autoflake
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Scripts\autoflake.EXE\__main__.py", line 7, in <module>
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Lib\site-packages\autoflake.py", line 1599, in main
    return _main(
           ^^^^^^
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Lib\site-packages\autoflake.py", line 1513, in _main
    args, success = merge_configuration_file(args)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Lib\site-packages\autoflake.py", line 1275, in merge_configuration_file
    config = find_and_process_config(flag_args)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Lib\site-packages\autoflake.py", line 1234, in find_and_process_config
    config = processor(config_file_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sterg\.cache\pre-commit\repop8j70l5p\py_env-default\Lib\site-packages\autoflake.py", line 1211, in process_config_file
    reader.read(config_file_path)
  File "C:\Users\sterg\miniforge3\envs\honegumi\Lib\configparser.py", line 713, in read
    self._read(fp, filename)
  File "C:\Users\sterg\miniforge3\envs\honegumi\Lib\configparser.py", line 1036, in _read
    for lineno, line in enumerate(fp, start=1):
  File "C:\Users\sterg\miniforge3\envs\honegumi\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 295: character maps to <undefined>

For now I'm just disabling the hook instead of trying to debug further (already tried with new environments).

@fsouza
Copy link
Collaborator

fsouza commented Mar 12, 2024

Ugh I think that's because we're trying to decode setup.cfg with cp1252 and you likely have non-ascii characters in the setup.cfg file. Perhaps we should just set encoding to "utf-8".

@fsouza fsouza added the bug label Mar 12, 2024
fsouza added a commit that referenced this issue Mar 13, 2024
This should fix an issue on Window where the `setup.cfg` can contain
non-ascii characters, and Python is trying to use cp1252. This should be
safe as utf-8 is compatible with cp1252.

It's possible I'll eat my words and some other platform breaks with this
change, but let's try.

Closes #294.
fsouza added a commit that referenced this issue Mar 13, 2024
This should fix an issue on Window where the `setup.cfg` can contain
non-ascii characters, and Python is trying to use cp1252. This should be
safe as utf-8 is compatible with cp1252.

It's possible I'll eat my words and some other platform breaks with this
change, but let's try.

Closes #294.
fsouza added a commit that referenced this issue Mar 13, 2024
This should fix an issue on Window where the `setup.cfg` can contain
non-ascii characters, and Python is trying to use cp1252. This should be
safe as utf-8 is compatible with cp1252.

It's possible I'll eat my words and some other platform breaks with this
change, but let's try.

Closes #294.
@fsouza fsouza closed this as completed in 2f53416 Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants