From 3dae1bfafe89c79318ce086d6cbe51de73c316e6 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:27:58 -0700 Subject: [PATCH 1/3] Configure output streams to support non-Unicode encodings Fixes a bug where Unicode characters in Augur's help output would result in an unhelpful error. This isn't expected to happen for most users. At the expense of those users, keep using Unicode characters; for them, print replacement characters. --- augur/__main__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/augur/__main__.py b/augur/__main__.py index 574061f29..f763b5e3b 100644 --- a/augur/__main__.py +++ b/augur/__main__.py @@ -2,11 +2,16 @@ Stub function and module used as a setuptools entry point. """ +import sys import augur from sys import argv, exit # Entry point for setuptools-installed script and bin/augur dev wrapper. def main(): + # Support non-Unicode encodings by replacing Unicode characters instead of erroring. + sys.stdout.reconfigure(errors="backslashreplace") + sys.stderr.reconfigure(errors="backslashreplace") + return augur.run( argv[1:] ) # Run when called as `python -m augur`, here for good measure. From 2f206a24bb79d3d2a7493e4cfbe62ec8df95bc90 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:39:56 -0700 Subject: [PATCH 2/3] Update changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a898cd071..3bc599cfa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,8 +5,10 @@ ### Bug fixes * distance: Improve documentation by describing how gaps get treated as indels and how users can ignore specific characters in distance calculations. [#1285][] (@huddlej) +* Fix help output compatibility with non-Unicode streams. [#1290][] (@victorlin) [#1285]: https://github.com/nextstrain/augur/pull/1285 +[#1290]: https://github.com/nextstrain/augur/pull/1290 ## 22.3.0 (14 August 2023) From fd8516816d95fea9e5c08a901a358b0a024f5521 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 23 Aug 2023 12:47:53 -0700 Subject: [PATCH 3/3] Explicitly enable universal newlines --- augur/__main__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/augur/__main__.py b/augur/__main__.py index f763b5e3b..d69eae231 100644 --- a/augur/__main__.py +++ b/augur/__main__.py @@ -8,9 +8,18 @@ # Entry point for setuptools-installed script and bin/augur dev wrapper. def main(): - # Support non-Unicode encodings by replacing Unicode characters instead of erroring. - sys.stdout.reconfigure(errors="backslashreplace") - sys.stderr.reconfigure(errors="backslashreplace") + sys.stdout.reconfigure( + # Support non-Unicode encodings by replacing Unicode characters instead of erroring. + errors="backslashreplace", + + # Explicitly enable universal newlines mode so we do the right thing. + newline=None, + ) + # Apply the above to stderr as well. + sys.stderr.reconfigure( + errors="backslashreplace", + newline=None, + ) return augur.run( argv[1:] )