From 93f2a1330af45bac70be663fd66abbcfe8e13438 Mon Sep 17 00:00:00 2001 From: bjones1 Date: Tue, 20 Jun 2017 16:20:11 -0500 Subject: [PATCH] Fix: Correct encoding bug producing unnecessary newlines on Python 3.6, Windows 10. --- runestone/__main__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runestone/__main__.py b/runestone/__main__.py index 556ded3dc..a29541204 100644 --- a/runestone/__main__.py +++ b/runestone/__main__.py @@ -55,6 +55,12 @@ def init(): paver_final = paver_stuff.decode('utf-8') % conf_dict config_final = config_stuff.decode('utf-8') % conf_dict + # On Windows, Python 3.6, the bytes read from ``template_base_dir`` and ``config_stuff`` contain Windows-style ``\n\r``. Unfortunately, `resource_string `_ does no universal newline support, so these remain intact. When written out, this is changed to ``\n\n``, making the file double-spaced. Python 3's `StringIO `_ class provides universal newline support, while Python 2's `StringIO `__ doesn't. + if six.PY3: + # Per the `TextIOWrapper docs `_, ``newline=None`` selects universal newline mode. The Python 3 StringIO_ class's ``newline`` argument works the same. + paver_final = six.StringIO(paver_final, newline=None).read() + config_final = six.StringIO(config_final, newline=None).read() + with open('pavement.py','w') as pvf: pvf.write(paver_final)