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

Printing the "knife" emoji crashes when the codepage doesn't support it #82

Closed
pfmoore opened this issue Nov 1, 2018 · 2 comments
Closed

Comments

@pfmoore
Copy link
Contributor

pfmoore commented Nov 1, 2018

On Windows, the console supports UTF8, and since Python 3.6 console output does too. But output to a pipe or file (and presumably any other case where the output doesn't support full Unicode, such as a Unix system with an encoding other than UTF-8 specified) crashes:

>shiv shiv >a.txt
Traceback (most recent call last):
  File "C:\[...]\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\[...]\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Utils\Misc\shiv.pyz\__main__.py", line 3, in <module>
  File "C:\Utils\Misc\shiv.pyz\_bootstrap\__init__.py", line 137, in bootstrap
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\shiv\cli.py", line 150, in main
    click.secho(" shiv! " + SHIV, bold=True)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\termui.py", line 420, in secho
    return echo(style(text, **styles), file=file, nl=nl, err=err, color=color)
  File "C:\[...]\.shiv\shiv_fbaa7543-371f-4f00-99fc-7a416dfdc32a\site-packages\click\utils.py", line 259, in echo
    file.write(message)
  File "C:\[...]\Python37\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f52a' in position 7: character maps to <undefined>

Something like the following fix to cli.py should address the issue:

# This is the 'knife' emoji
SHIV = u"\U0001F52A"
try:
    SHIV.encode(sys.stdout.encoding)
except UnicodeEncodeError:
    SHIV = "!"
lorencarvalho added a commit that referenced this issue Nov 1, 2018
@lorencarvalho
Copy link
Contributor

tbqh I've always been annoyed at myself for including the emoji and the begin/end output. just cut a PR to remove them entirely

I've thought about even suppressing pip's output (via -q) by default in favor of a -v to opt into verbosity, perhaps in a later change...

lorencarvalho added a commit that referenced this issue Nov 1, 2018
lorencarvalho added a commit that referenced this issue Nov 1, 2018
@pfmoore
Copy link
Contributor Author

pfmoore commented Nov 1, 2018

Cool, the emoji is cute (there's a few projects that seem to have started doing the same) but unfortunately there's still some places that don't support it cleanly - so it's a bit of a "more effort than it's worth" case, I guess.

lorencarvalho added a commit that referenced this issue Nov 2, 2018
lorencarvalho added a commit that referenced this issue Nov 3, 2018
lorencarvalho added a commit that referenced this issue Nov 3, 2018
lorencarvalho added a commit that referenced this issue Nov 3, 2018
lorencarvalho added a commit that referenced this issue Nov 3, 2018
lorencarvalho added a commit that referenced this issue Nov 3, 2018
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

2 participants