From 8aceae428e955ea72eda97abd5c7889f012e779c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 20 Mar 2019 23:50:46 -0400 Subject: [PATCH] py3: make setup.py gui work Apparently compileUi explicitly opens the file/buffer as unicode, not bytes, and then writes a unicode header string (containing the source file). So the previous attempt to use BytesIO was wrong in this case. Also images.qrc is being constructed completely in the right here and now from a bunch of unicode strings, so just use exactly that. --- setup/gui.py | 2 +- src/calibre/gui2/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/gui.py b/setup/gui.py index 1c9c5aefd9..4b6a86126e 100644 --- a/setup/gui.py +++ b/setup/gui.py @@ -58,7 +58,7 @@ class GUI(Command): for s in sources: files.append('%s'%s) manifest = '\n\n%s\n\n'%'\n'.join(sorted(files)) - with open('images.qrc', 'wb') as f: + with open('images.qrc', 'w') as f: f.write(manifest) finally: os.chdir(cwd) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index d16d949c43..1f5325d8d5 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1288,7 +1288,7 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False): if force_compile or not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime: if not summary: info('\tCompiling form', form) - buf = io.BytesIO() + buf = io.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('import images_rc', '') @@ -1298,7 +1298,7 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False): dat = dat.replace('_("d MMM yyyy")', '"d MMM yyyy"') dat = pat.sub(sub, dat) - open(compiled_form, 'wb').write(dat) + open(compiled_form, 'w').write(dat) num += 1 if num: info('Compiled %d forms' % num)