From 513fbb1539ce1a0b5547901357e9c7afaedefc3c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 26 Mar 2015 07:57:39 +0100 Subject: [PATCH] Make setup.py work with python2. This is needed for distributions (Debian/Ubuntu) which only have a python2 tox. Tests will still be run with python3, but the setup will be called with python2. --- scripts/setupcommon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py index 0be88d695..4fa4539fb 100644 --- a/scripts/setupcommon.py +++ b/scripts/setupcommon.py @@ -29,13 +29,20 @@ import subprocess sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) +if sys.hexversion >= 0x03000000: + _open = open +else: + import codecs + _open = codecs.open + + BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir) def read_file(name): """Get the string contained in the file named name.""" - with open(name, 'r', encoding='utf-8') as f: + with _open(name, 'r', encoding='utf-8') as f: return f.read() @@ -88,7 +95,7 @@ def write_git_file(): if gitstr is None: gitstr = '' path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id') - with open(path, 'w', encoding='utf-8') as f: + with _open(path, 'w', encoding='ascii') as f: f.write(gitstr)