From 2c24c87a344c4bc45d421b317b90c05640c1ac51 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 18 Nov 2016 19:24:44 +0300 Subject: [PATCH] Use print() function for python 2/3 compatibility Also remove trailing spaces. --- setup.py | 62 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/setup.py b/setup.py index 180d697..1675d88 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +from __future__ import print_function from distutils.cmd import Command from distutils.core import setup from distutils.util import split_quoted @@ -23,26 +24,26 @@ def __init__(self, *a, **kw): self._mysql_link_args = [] self.get_mysql_compile_args = self.get_mysql_link_args = None Extension.__init__(self, *a, **kw) - + def _get_extra_compile_args(self): if not self._mysql_compile_args and self.get_mysql_compile_args: self._mysql_compile_args = self.get_mysql_compile_args() return self._extra_compile_args + self._mysql_compile_args - + def _set_extra_compile_args(self, args): self._extra_compile_args = args - + extra_compile_args = property( _get_extra_compile_args, _set_extra_compile_args) - + def _get_extra_link_args(self): if not self._mysql_link_args and self.get_mysql_link_args: self._mysql_link_args = self.get_mysql_link_args() return self._extra_link_args + self._mysql_link_args - + def _set_extra_link_args(self, args): self._extra_link_args = args - + extra_link_args = property(_get_extra_link_args, _set_extra_link_args) oursql_ext = MysqlExtension("oursql", ["oursqlx/compat.c"]) @@ -50,7 +51,7 @@ def _set_extra_link_args(self, args): try: from Cython.Distutils import build_ext except ImportError: - print "cython not found, using previously-cython'd .c file." + print("cython not found, using previously-cython'd .c file.") oursql_ext.sources.insert(0, 'oursqlx/oursql.c') else: oursql_ext.sources.insert(0, 'oursqlx/oursql.pyx') @@ -59,7 +60,7 @@ def _set_extra_link_args(self, args): class oursql_build_ext(build_ext): user_options = build_ext.user_options + [ - ('mysql-config=', None, + ('mysql-config=', None, '(*nix only) path to the mysql-config executable'), ('use-libmysqld', None, '(*nix only) link against libmysqld instead of libmysqlclient'), @@ -72,29 +73,29 @@ class oursql_build_ext(build_ext): '(Windows only) the path to the mysql installation; can be given ' 'instead of --mysql-registry-key'), ] - + boolean_options = build_ext.boolean_options + [ 'use-libmysqld', 'static' ] - + def initialize_options(self): build_ext.initialize_options(self) self.mysql_config = os.environ.get('MYSQL_CONFIG', 'mysql_config') self.use_libmysqld = self.static = 0 self.mysql_registry_key = r'SOFTWARE\MySQL AB\MySQL Server 5.0' self.mysql_root = None - + def get_mysql_config(self, option): args = [self.mysql_config, '--%s' % option] - print ' '.join(args) + print(' '.join(args)) try: proc = subprocess.Popen(args, stdout=subprocess.PIPE) except: - print 'failed to execute', args[0] + print('failed to execute', args[0]) raise stdout, _ = proc.communicate() return split_quoted(stdout.strip()) - + def setup_posixish(self, ext): ext.get_mysql_compile_args = ( lambda: self.get_mysql_config('cflags')) @@ -104,7 +105,7 @@ def setup_posixish(self, ext): else: ext.get_mysql_link_args = ( lambda: self.get_mysql_config('libs')) - + def setup_windowsish(self, ext): if self.mysql_root: mysql_root = self.mysql_root @@ -112,7 +113,7 @@ def setup_windowsish(self, ext): mysql_key = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, self.mysql_registry_key) mysql_root, _ = _winreg.QueryValueEx(mysql_key, 'Location') - + if self.static: client = "mysqlclient" else: @@ -129,19 +130,19 @@ def setup_windowsish(self, ext): else: ext.get_mysql_compile_args = lambda: ['/MD'] - + def build_extension(self, ext): if getattr(ext, 'use_mysql_flags', False): try: # distribute/setuptools flip out if I try to open(os.devnull), # so, I work around their stupidity by using a pipe instead. - proc = subprocess.Popen([self.mysql_config], + proc = subprocess.Popen([self.mysql_config], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) except OSError: if _winreg: self.setup_windowsish(ext) else: - print ('warning: no usable mysql_config and no _winreg ' + print('warning: no usable mysql_config and no _winreg ' 'module to try; hopefully you have usable ' 'CFLAGS/LDFLAGS set.') else: @@ -170,19 +171,19 @@ class ZipWithLicense(Command): description = 'zip binary installer with the license' user_options = [] boolean_options = [] - + def initialize_options(self): pass - + def finalize_options(self): pass - + def run(self): license = open(os.path.join( os.path.dirname(os.path.abspath(__file__)), 'COPYING')).read() license = '\r\n'.join(license.splitlines()) fullname = self.distribution.get_fullname() - + dist_files = getattr(self.distribution, 'dist_files', None) if dist_files is None: dist_files = [] @@ -190,7 +191,7 @@ def run(self): if command.startswith('bdist_'): dist_files.append( (None, None, cmd_obj.get_installer_filename(fullname))) - + new_dist_files = [] for command, pyversion, filename in dist_files: out_filename = os.path.splitext(filename)[0] + '.zip' @@ -211,13 +212,13 @@ def run(self): url='http://launchpad.net/oursql', description='MySQL bindings for python.', long_description=""" - oursql is a set of MySQL bindings for python 2.4+ with a focus on - wrapping the `MYSQL_STMT API`__ to provide real parameterization and + oursql is a set of MySQL bindings for python 2.4+ with a focus on + wrapping the `MYSQL_STMT API`__ to provide real parameterization and real server-side cursors. MySQL 4.1.2 or better is required. - + __ http://dev.mysql.com/doc/refman/5.0/en/c-api-prepared-statements.html - - There's extensive documentation available online at + + There's extensive documentation available online at http://packages.python.org/oursql/. """, classifiers=[ @@ -227,9 +228,10 @@ def run(self): 'Programming Language :: C', 'Programming Language :: Cython', 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', 'Topic :: Database :: Database Engines/Servers', ], - + ext_modules=[oursql_ext], cmdclass=oursql_commands, )