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

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

Open
bkeryan opened this issue Mar 5, 2024 · 0 comments
Open

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

bkeryan opened this issue Mar 5, 2024 · 0 comments

Comments

@bkeryan
Copy link
Contributor

bkeryan commented Mar 5, 2024

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant