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

Enforce UTF-8 encoding for linter subprocess on Windows #69

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

Conversation

akaihola
Copy link
Owner

On Windows, linting UTF-8 files with non-ASCII characters fails. This patch enforces UTF-8 encoding when calling linter subprocesses.

$ graylint -L pylint src
Exception on node <Call l.341 at 0x1fb7ece0610> in file 'tmp437lpsx3\baseline-revision\darkgraylib\src\darkgraylib\tests\test_git.py'
Traceback (most recent call last):
  File "pylint\utils\ast_walker.py", line 91, in walk
    callback(astroid)
  File "pylint\checkers\refactoring\refactoring_checker.py", line 1161, in visit_call
    self._check_use_dict_literal(node)
  File "pylint\checkers\refactoring\refactoring_checker.py", line 1727, in _check_use_dict_literal
    self.add_message(
  File "pylint\checkers\base_checker.py", line 153, in add_message
    self.linter.add_message(
  File "pylint\lint\pylinter.py", line 1270, in add_message
    self._add_one_message(
  File "pylint\lint\pylinter.py", line 1228, in _add_one_message
    self.reporter.handle_message(
  File "pylint\reporters\text.py", line 161, in handle_message
    self.write_message(msg)
  File "pylint\reporters\text.py", line 154, in write_message
    self.writeln(self._fixed_template.format(**self_dict))
  File "pylint\reporters\base_reporter.py", line 45, in writeln
    print(string, file=self.out)
  File "Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 145-148: character maps to <undefined>
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 22] Invalid argument
ERROR:graylint.__main__:'utf-8' codec can't decode byte 0xe9 in position 2838: invalid continuation byte (123)
Traceback (most recent call last):
  File "graylint\src\graylint\__main__.py", line 29, in main_with_error_handling
    return main(argv)
           ^^^^^^^^^^
  File "graylint\src\graylint\__main__.py", line 53, in main
    linter_failures_on_modified_lines = run_linters(
                                        ^^^^^^^^^^^^
  File "graylint\src\graylint\linting.py", line 423, in run_linters
    # 10. first do a temporary checkout at `rev1` and run linter subprocesses once for
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "graylint\src\graylint\linting.py", line 562, in _get_messages_from_linters_for_baseline
    tmp_path = Path(tmpdir) / "baseline-revision" / root.name
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "graylint\src\graylint\linting.py", line 473, in _get_messages_from_linters
    """

  File "graylint\src\graylint\linting.py", line 351, in run_linter
    #     modified or unmodified, to get current linting status in the working tree
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2838: invalid continuation byte

@akaihola akaihola added the bug Something isn't working label Nov 16, 2024
@akaihola akaihola added this to the Graylint 2.0.1 milestone Nov 16, 2024
@akaihola akaihola self-assigned this Nov 16, 2024
@akaihola akaihola changed the title fix: enforce UTF-8 encoding for linter subprocess on Windows Enforce UTF-8 encoding for linter subprocess on Windows Nov 16, 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
Development

Successfully merging this pull request may close these issues.

1 participant