Skip to content

Use print() function for python 2/3 compatibility #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,34 +24,34 @@ 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"])

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')
Expand All @@ -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'),
Expand All @@ -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'))
Expand All @@ -104,15 +105,15 @@ 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
else:
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:
Expand All @@ -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:
Expand Down Expand Up @@ -170,27 +171,27 @@ 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 = []
for command, cmd_obj in self.distribution.command_obj.iteritems():
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'
Expand All @@ -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=[
Expand All @@ -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,
)