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

pre-commit yaml linter python code is not supporting persian yaml files (not supporting utf8) #265

Open
BaseMax opened this issue Nov 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@BaseMax
Copy link
Member

BaseMax commented Nov 3, 2024

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 445: character maps to

image

C:\Users\MAX\Salam>git commit -m "lint and format on all yaml files"
identity.................................................................Passed
- hook id: identity
- duration: 0.39s

config/language.yaml
config/layout/attribute/type.yaml
config/layout/attribute/style/type.yaml
config/layout/type.yaml
config/layout/attribute/style/state.yaml
config/layout/attribute/style/global_value.yaml
config/layout/attribute/style/value.yaml
config/type.yaml

Check hooks apply to the repository..................(no files to check)Skipped
black................................................(no files to check)Skipped
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check that executables have shebangs.....................................Passed
check illegal windows names..........................(no files to check)Skipped
check for merge conflicts................................................Passed
check that scripts with shebangs are executable..........................Passed
check vcs permalinks.....................................................Passed
check yaml...............................................................Passed
detect destroyed symlinks................................................Passed
detect aws credentials...................................................Passed
detect private key.......................................................Passed
fix end of files.........................................................Passed
fix utf-8 byte order marker..............................................Passed
forbid submodules....................................(no files to check)Skipped
mixed line ending........................................................Passed
trim trailing whitespace.................................................Passed
codespell................................................................Passed
Markdown Link Check..................................(no files to check)Skipped
Run markdownlint.....................................(no files to check)Skipped
Run yamllint.............................................................Failed
- hook id: yamllint
- 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\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Scripts\yamllint.EXE\__main__.py", line 7, in <module>
  File "C:\Users\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Lib\site-packages\yamllint\cli.py", line 223, in run
    problems = linter.run(f, conf, filepath)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Lib\site-packages\yamllint\linter.py", line 232, in run
    content = input.read()
              ^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2032.0_x64__qbz5n2kfra8p0\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 61: character maps to <undefined>
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\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Scripts\yamllint.EXE\__main__.py", line 7, in <module>
  File "C:\Users\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Lib\site-packages\yamllint\cli.py", line 223, in run
    problems = linter.run(f, conf, filepath)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MAX\.cache\pre-commit\repol2sbu8ft\py_env-python3\Lib\site-packages\yamllint\linter.py", line 232, in run
    content = input.read()
              ^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2032.0_x64__qbz5n2kfra8p0\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 445: character maps to <undefined>

clang-format.........................................(no files to check)Skipped
@BaseMax
Copy link
Member Author

BaseMax commented Nov 3, 2024

I changed that line and added encoding option as following:
with open(file, newline='', encoding='utf-8') as f:

and the problem has been fixed.

We need to hack python yamllint or send a merge request to that package.

@BaseMax
Copy link
Member Author

BaseMax commented Nov 3, 2024

The patch has been sent.

adrienverge/yamllint#696

@jbampton jbampton added the bug Something isn't working label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants