Skip to content

fix can't handle source files encoded as UTF-8 #168

@bkeryan

Description

@bkeryan

We are adding a nidaqmx-python test containing localized strings:

@pytest.mark.parametrize(
    "device_name, supported_encodings",
    [
        ("Gerät", ["1252", "iso-8859-1", "utf-8"]),
        ("l' appareil", ["1252", "iso-8859-1", "utf-8"]),
        ("デバイス", ["932", "shift-jis", "utf-8"]),
        ("장치", ["utf-8", "euc-kr"]),
        ("设备", ["utf-8", "gbk"]),
    ],
)
...

Reformatting this test with ni-python-styleguide fix fails with this error:

PS D:\dev\nidaqmx-python> poetry run ni-python-styleguide fix
All done! ✨ 🍰 ✨
1 file left unchanged.
Traceback (most recent call last):
  File "C:\Users\Administrator\.pyenv\pyenv-win\versions\3.9.13\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Administrator\.pyenv\pyenv-win\versions\3.9.13\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\dev\nidaqmx-python\.venv\Scripts\ni-python-styleguide.exe\__main__.py", line 7, in <module>
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\click\decorators.py", line 45, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\ni_python_styleguide\_cli.py", line 186, in fix
    _fix.fix(
  File "D:\dev\nidaqmx-python\.venv\lib\site-packages\ni_python_styleguide\_fix.py", line 146, in fix
    raise Exception(
Exception: Failed to format files:
D:\dev\nidaqmx-python\tests\acceptance\test_internationalization.py: 'charmap' codec can't decode byte 0x90 in position 996: character maps to <undefined>

Workarounds:

  • Fix errors manually. ni-python-styleguide lint doesn't seem to have this problem.
  • Avoid UTF-8 in source files. Use "\uXXXX" escapes instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions