Skip to content
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

Support unixodbc in Mac OSX #19

Merged
merged 2 commits into from
May 10, 2014
Merged
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
60 changes: 37 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/python

import sys, os, re, platform
from os.path import exists, abspath, dirname, join, isdir
import os
import re
import subprocess as subp
import sys

from os.path import exists, abspath, dirname, join

try:
# Allow use of setuptools so eggs can be built.
Expand Down Expand Up @@ -33,7 +37,7 @@ def finalize_options(self):
def run(self):
version_str, version = get_version()
sys.stdout.write(version_str + '\n')


class TagsCommand(Command):

Expand All @@ -53,7 +57,7 @@ def run(self):
files = [ join('src', f) for f in os.listdir('src') if f.endswith(('.h', '.cpp')) ]
cmd = 'etags %s' % ' '.join(files)
return os.system(cmd)



def main():
Expand All @@ -74,10 +78,10 @@ def main():

'long_description': ('A Python DB API 2 module for ODBC. This project provides an up-to-date, '
'convenient interface to ODBC using native data types like datetime and decimal.'),

'maintainer': "Michael Kleehammer",
'maintainer_email': "michael@kleehammer.com",

'ext_modules': [Extension('pyodbc', files, **settings)],

'license': 'MIT',
Expand All @@ -99,7 +103,7 @@ def main():
'cmdclass': { 'version' : VersionCommand,
'tags' : TagsCommand }
}

if sys.hexversion >= 0x02060000:
kwargs['options'] = {
'bdist_wininst': {'user_access_control' : 'auto'}
Expand Down Expand Up @@ -144,16 +148,26 @@ def get_compiler_settings(version_str):
settings['libraries'].append('odbc32')

elif sys.platform == 'darwin':
# OS/X now ships with iODBC.
settings['libraries'].append('iodbc')

# Apple has decided they won't maintain the iODBC system in OS/X and has added deprecation warnings in 10.8.
# For now target 10.7 to eliminate the warnings.

# Python functions take a lot of 'char *' that really should be const. gcc complains about this *a lot*
IODBC = 'iodbc'
UNIXODBC = 'odbc.2'
odbc_lib = IODBC # OS/X ships with iODBC, so default to that lib.

# Determine if unixODBC is installed and use that instead if available.
proc = subp.Popen(('gcc', '-l{0}'.format(UNIXODBC)), stderr=subp.PIPE)
_, stderr = proc.communicate()
if 'ld: library not found for' not in stderr:
odbc_lib = UNIXODBC
settings['libraries'].append(odbc_lib)

# Python functions take a lot of 'char *' that really should be const.
# gcc complains about this *a lot*.
settings['extra_compile_args'] = ['-Wno-write-strings', '-Wno-deprecated-declarations']

settings['define_macros'].append( ('MAC_OS_X_VERSION_10_7',) )
# Apple has decided they won't maintain the iODBC system in OS/X
# and has added deprecation warnings in 10.8.
# For now target 10.7 to eliminate the warnings with iODBC.
if odbc_lib == 'iodbc':
settings['define_macros'].append( ('MAC_OS_X_VERSION_10_7',) )

else:
# Other posix-like: Linux, Solaris, etc.
Expand All @@ -172,15 +186,15 @@ def add_to_path():
Prepends the build directory to the path so pyodbcconf can be imported without installing it.
"""
# Now run the utility

import imp
library_exts = [ t[0] for t in imp.get_suffixes() if t[-1] == imp.C_EXTENSION ]
library_names = [ 'pyodbcconf%s' % ext for ext in library_exts ]
# Only go into directories that match our version number.

# Only go into directories that match our version number.

dir_suffix = '-%s.%s' % (sys.version_info[0], sys.version_info[1])

build = join(dirname(abspath(__file__)), 'build')

for top, dirs, files in os.walk(build):
Expand All @@ -189,7 +203,7 @@ def add_to_path():
if name in files:
sys.path.insert(0, top)
return

raise SystemExit('Did not find pyodbcconf')


Expand Down Expand Up @@ -234,7 +248,7 @@ def get_version():
name, numbers = '3.0.0-unsupported', [3,0,0,0]

return name, numbers


def _get_version_pkginfo():
filename = join(dirname(abspath(__file__)), 'PKG-INFO')
Expand All @@ -261,7 +275,7 @@ def _get_version_git():
if not match:
return None, None

numbers = [int(n or OFFICIAL_BUILD) for n in match.groups()]
numbers = [int(n_ or OFFICIAL_BUILD) for n_ in match.groups()]
if numbers[-1] == OFFICIAL_BUILD:
name = '%s.%s.%s' % tuple(numbers[:3])
if numbers[-1] != OFFICIAL_BUILD:
Expand Down