tonybaloney / wily

A Python application for tracking, reporting on timing and complexity in Python code
Apache License 2.0
1.21k stars 59 forks source link

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

Closed devdanzin closed 1 year ago

devdanzin commented 1 year ago

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 commented 1 year ago

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%) :arrow_up:
src/wily/commands/diff.py 89.15% <100.00%> (+0.26%) :arrow_up:
src/wily/commands/index.py 100.00% <100.00%> (ø)
src/wily/commands/list_metrics.py 88.88% <100.00%> (+1.38%) :arrow_up:
src/wily/commands/rank.py 96.55% <100.00%> (+0.12%) :arrow_up:
src/wily/helper/__init__.py 100.00% <100.00%> (ø)
tonybaloney commented 1 year ago

Thanks, this is a nice clean solution