guilatrova / tryceratops

A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when displaying the output on Windows in Anaconda

Pierre-Sassoulas opened this issue · comments

It seems there can be an encoding issue with the text in "Done processing" on Windows with anaconda:

File "C:\Users\anon\.cache\pre-commit\repoqfqlxkvs\py_env-python3\lib\site-packages\tryceratops\interfaces.py", line 50, in _present_status
    print("Done processing! \U0001f996\u2728")
  File "c:\Users\anon\anaconda3\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 17-18: character maps to <undefined>

@Pierre-Sassoulas I believe it's a known issue in Windows. Can you try this and let me know if it solves your issue?

#33 (comment)

I'll leave this issue open. Probably the best solution here would be to not display emojis on Windows.

Sorry I can't test on windows I'm not the original reporter and I'm on linux. It affected all our windows users. set PYTHONIOENCODING=UTF-8 would not be a reasonable solution, we expect the pre-commit hook to work without modification. I like the solution of not displaying emojis if there is a problem though 👍 .

You're right, I was brainstorming with @willmcgugan about ways to solve that.

To resolve it faster, I believe I'll just remove the emojis for now.

Emojis are nice though :) You can also catch the UnicodeEncodeError and provide an alternative message if the emojis don't run properly. Or check how black (the python formatter) does it, they have emojis and it works on all Windows terminal.

@Pierre-Sassoulas
Very soon you'll have a new version without emojis. In order to unblock you and any other users facing the same problem, I preferred to remove it right away.

I saw that black uses a function from the click lib: echo. I'll take some time to dig deeper later.