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

Avoid using unicode characters if sys.stdout doesn't support them (fix #65) #200

Merged
merged 5 commits into from
Jul 17, 2023

Conversation

devdanzin
Copy link
Collaborator

@devdanzin devdanzin commented Jul 15, 2023

When piping wily's output (and in other related scenarios) in Windows, users get a UnicodeEncodeError: 'charmap' codec can't encode characters... error. This happens because the DEFAULT_GRID_STYLE is "fancy_grid", which uses characters outside of what charmap can understand.

This PR introduces checks for sys.stdout.encoding and, if it's not UTF-8, makes wily pass "grid" instead of "fancy_grid" to tabulate as tablefmt. It gives comparable output with ASCII-only characters.

Output should be testable once #199 lands.

Fixes #65.

@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2023

Codecov Report

Merging #200 (2b1ac8a) into master (2f59f94) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
+ Coverage   95.26%   95.32%   +0.05%     
==========================================
  Files          23       24       +1     
  Lines        1226     1241      +15     
  Branches      276      278       +2     
==========================================
+ Hits         1168     1183      +15     
  Misses         33       33              
  Partials       25       25              
Impacted Files Coverage Δ
src/wily/__main__.py 95.58% <100.00%> (+0.04%) ⬆️
src/wily/commands/diff.py 89.15% <100.00%> (+0.26%) ⬆️
src/wily/commands/index.py 100.00% <100.00%> (ø)
src/wily/commands/list_metrics.py 88.88% <100.00%> (+1.38%) ⬆️
src/wily/commands/rank.py 96.55% <100.00%> (+0.12%) ⬆️
src/wily/helper/__init__.py 100.00% <100.00%> (ø)

@tonybaloney
Copy link
Owner

Thanks, this is a nice clean solution

@tonybaloney tonybaloney merged commit 5c24894 into tonybaloney:master Jul 17, 2023
19 checks passed
@devdanzin devdanzin deleted the fix_encode_error branch July 17, 2023 04:37
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.

Wily diff output
3 participants