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

Bug check-toml ASCII on Windows #474

Closed
staticdev opened this issue May 13, 2020 · 3 comments · Fixed by #479
Closed

Bug check-toml ASCII on Windows #474

staticdev opened this issue May 13, 2020 · 3 comments · Fixed by #479

Comments

@staticdev
Copy link

I run pre-commit-hooks on my CI using Linux, Windows and Mac. When I have ASCII characters on it in Windows, it gives me an error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 148: character maps to <undefined>

The ASCII character is in the author name from this file: https://github.com/staticdev/toml-validator/blob/master/pyproject.toml

When I remove the Á from the name, the error vanishes. This is a bug.

@asottile
Copy link
Member

can you show your configuration and output?

@staticdev
Copy link
Author

staticdev commented May 13, 2020

@asottile Sure!

Configuration:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.5.0
    hooks:
      - id: check-toml
      - id: check-yaml
      - id: end-of-file-fixer
      - id: trailing-whitespace
      - id: check-added-large-files
  - repo: https://github.com/prettier/prettier
    rev: 2.0.5
    hooks:
      - id: prettier
  - repo: https://github.com/psf/black
    rev: 19.10b0
    hooks:
      - id: black
  - repo: https://gitlab.com/pycqa/flake8
    rev: 3.7.9
    hooks:
      - id: flake8
        additional_dependencies:
          - flake8-bandit==2.1.2
          - flake8-bugbear==20.1.4
          - flake8-docstrings==1.5.0
          - pep8-naming==0.10.0
          - darglint==1.2.3
  - repo: https://github.com/asottile/reorder_python_imports
    rev: v2.3.0
    hooks:
      - id: reorder-python-imports
        args: [--application-directories=src]

Output:

Check Toml...............................................................Failed
- hook id: check-toml
- exit code: 1

Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.8.2\x64\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\hostedtoolcache\windows\python\3.8.2\x64\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\runneradmin\.cache\pre-commit\repomo8xk8q_\py_env-python3.8\Scripts\check-toml.EXE\__main__.py", line 7, in <module>
  File "c:\users\runneradmin\.cache\pre-commit\repomo8xk8q_\py_env-python3.8\lib\site-packages\pre_commit_hooks\check_toml.py", line 20, in main
    toml.load(f)
  File "c:\users\runneradmin\.cache\pre-commit\repomo8xk8q_\py_env-python3.8\lib\site-packages\toml\decoder.py", line 134, in load
    return loads(f.read(), _dict, decoder)
  File "c:\hostedtoolcache\windows\python\3.8.2\x64\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 148: character maps to <undefined>

@asottile
Copy link
Member

thanks! that's helpful, I believe this just needs an encoding='UTF-8' argument to the open call -- would you like to submit a patch and test for this (I can help with the test as well!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants