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

Better Unicode / emoji capability detection #614

Merged
merged 20 commits into from
Feb 2, 2021

Conversation

itsayellow
Copy link
Contributor

@itsayellow itsayellow commented Jan 26, 2021

  • I have added an entry to docs/changelog.md

Summary of changes

Closes #73.

Previously we only disallowed emojis (Unicode characters) when we detected Windows, and allowed for all other platforms. This ignored the fact that some shells in Windows are now perfectly happy displaying emojis/Unicode, while some non-Windows platforms' shells are not using a Unicode encoding and actually crash when we try to print emoji (See #73.)

This PR actually directly tests encoding our emoji unicode characters using sys.stderr.encoding to determine if it will work on a platform.

Test plan

Uninstalling a nonexistent package will show the "sleep" emoji. This should omit the emoji and not yield an error if non-Unicode encoding is used in the shell. It should show an emoji if the shell has Unicode-capable encoding.

This PR:

(venv39) > pipx uninstall doesntexist           
Nothing to uninstall for doesntexist 😴
(venv39) > LANG=en_US pipx uninstall doesntexist
Nothing to uninstall for doesntexist 

pipx 0.16.0.0:

> pipx uninstall doesntexist
Nothing to uninstall for doesntexist 😴
> LANG=en_US pipx uninstall doesntexist
Traceback (most recent call last):
  File "/home/mclapp/.local/bin/pipx", line 8, in <module>
    sys.exit(cli())
  File "/home/mclapp/.local/lib/python3.9/site-packages/pipx/main.py", line 752, in cli
    return run_pipx_command(parsed_pipx_args)
  File "/home/mclapp/.local/lib/python3.9/site-packages/pipx/main.py", line 234, in run_pipx_command
    return commands.uninstall(venv_dir, constants.LOCAL_BIN_DIR, verbose)
  File "/home/mclapp/.local/lib/python3.9/site-packages/pipx/commands/uninstall.py", line 27, in uninstall
    print(f"Nothing to uninstall for {venv_dir.name} {sleep}")
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f634' in position 37: ordinal not in range(256)

@itsayellow itsayellow changed the title Unicode check Better Unicode / emoji capability detection Jan 26, 2021
@itsayellow
Copy link
Contributor Author

I moved the EMOJI_SUPPORT constant and detection into emojies.py because it seemed appropriate there, but if people like it to remain in constants.py I would be amenable to that.

@uranusjr
Copy link
Member

Is the plural of emoji emojis or emojies? The spelling is inconsistent between the commit message and the module name.

@itsayellow
Copy link
Contributor Author

itsayellow commented Jan 28, 2021

Is the plural of emoji emojis or emojies? The spelling is inconsistent between the commit message and the module name.

Yeahhhhhh. I was trying to ignore that 😛

https://www.theatlantic.com/technology/archive/2016/01/whats-the-plural-of-emoji-emojis/422763/

There is a correct answer, but no one has agreed on it yet.

It does seem that the plural is a choice between "emojis" and "emoji". So I'm going to rename the module "emojis" without the "e", since "emojies" seems unloved by everybody.

Another:
https://www.grammarly.com/blog/emojis-emoji/

@itsayellow itsayellow merged commit dd8b862 into pypa:master Feb 2, 2021
@itsayellow itsayellow deleted the unicode-check branch February 2, 2021 05:42
itsayellow added a commit to itsayellow/pipx that referenced this pull request Feb 16, 2021
Add app_name "pipx" to ensurepath comments, don't duplicate bin_paths.

Apply typing.NoReturn to code base (pypa#605)

Fix post-release development versioning (pypa#601)

Make constants.py single source for WINDOWS boolean. (pypa#607)

Add section on where pipx keeps its logs. (pypa#608)

Upgrade all pre-commit plugins except black. (pypa#611)

Fix show/hide cursor for older Windows (pypa#610)

Drop .exe appending on Windows (pypa#606)

This makes Venv.run_app() and code path along it accept an additional
argument, so we can distinguish between the "real" name (filename) of an
app, and the name supplied by the user.

This makes the code simpler, espacially when dealing with the proposed
[pipx.run] entry points.

Add text color capability for Windows (pypa#612)

Better Unicode / emoji capability detection (pypa#614)

Use python 3.9 as default python for CI. (pypa#622)

Don't show / hide cursor if not in tty. (pypa#620)
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

Successfully merging this pull request may close these issues.

Traceback when locale not set to UTF-8
2 participants