From bf0168357e8f1a7f95e59d2d8568e24ebb8406d8 Mon Sep 17 00:00:00 2001 From: Johannes Dewender Date: Tue, 28 Oct 2014 16:27:09 +0100 Subject: [PATCH] start compat.py This only includes what is needed in setup.py for now. At least encoding/decoding functions and more renamed imports are needed later on. --- picard/compat.py | 30 ++++++++++++++++++++++++++++++ setup.py | 9 ++------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 picard/compat.py diff --git a/picard/compat.py b/picard/compat.py new file mode 100644 index 000000000..02fa5a8a4 --- /dev/null +++ b/picard/compat.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# +# Picard, the next-generation MusicBrainz tagger +# Copyright (C) 2014 Johannes Dewender +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +"""Python 2/3 compatibility""" + +import sys + +is_py2 = (sys.version_info[0] == 2) +is_py3 = (sys.version_info[0] == 3) + +if is_py2: + from StringIO import StringIO +else: + from io import StringIO diff --git a/setup.py b/setup.py index c5ddf2e66..9f4d6a72b 100755 --- a/setup.py +++ b/setup.py @@ -7,12 +7,7 @@ import os import re import sys import subprocess -from picard import __version__ - -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from picard import __version__, compat if sys.version_info < (2, 6): print("*** You need Python 2.6 or higher to use Picard.") @@ -328,7 +323,7 @@ class picard_build_ui(Command): def compile_ui(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) - tmp = StringIO() + tmp = compat.StringIO() uic.compileUi(uifile, tmp) source = tmp.getvalue() rc = re.compile(r'\n\n#.*?(?=\n\n)', re.MULTILINE|re.DOTALL)