[r458]: branches / MySQLdb-1.2 / MySQLdb / setup.py  Maximize  Restore  History

Download this file

123 lines (101 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
class Abort(Exception): pass
import os
import sys
from distutils.core import setup
from distutils.extension import Extension
from ConfigParser import SafeConfigParser
if sys.version_info < (2, 3):
raise Abort, "Python-2.3 or newer is required"
config = SafeConfigParser()
config.read(['metadata.cfg', 'site.cfg'])
metadata = dict(config.items('metadata'))
options = dict(config.items('options'))
metadata['py_modules'] = filter(None, metadata['py_modules'].split('\n'))
metadata['classifiers'] = filter(None, metadata['classifiers'].split('\n'))
def mysql_config(what):
from os import popen
f = popen("mysql_config --%s" % what)
data = f.read().strip().split()
if f.close(): data = []
return data
# This dequote() business is required for some older versions
# of mysql_config
def dequote(s):
if s[0] in "\"'" and s[0] == s[-1]:
s = s[1:-1]
return s
def enabled(option):
value = options[option]
s = value.lower()
if s in ('yes','true','1','y'):
return True
elif s in ('no', 'false', '0', 'n'):
return False
else:
raise Abort, "Unknown value %s for option %s" % (value, option)
if os.name == "posix":
flag_prefix = "-"
else: # assume windows
flag_prefix = "/"
def compiler_flag(f): return flag_prefix + f
extra_objects = []
static = enabled('static')
if enabled('embedded'):
libs = mysql_config("libmysqld-libs")
client = "mysqld"
elif enabled('threadsafe'):
libs = mysql_config("libs_r")
client = "mysqlclient_r"
if not libs:
libs = mysql_config("libs")
client = "mysqlclient"
else:
libs = mysql_config("libs")
client = "mysqlclient"
name = "MySQL-%s" % os.path.basename(sys.executable)
if enabled('embedded'):
name = name + "-embedded"
metadata['name'] = name
library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("L")) ]
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
removable_compile_args = [ compiler_flag(f) for f in "ILl" ]
extra_compile_args = [ i for i in mysql_config("cflags")
if i[:2] not in removable_compile_args ]
include_dirs = [ dequote(i[2:])
for i in mysql_config('include')
if i.startswith(compiler_flag('I')) ]
if not include_dirs: # fix for MySQL-3.23
include_dirs = [ dequote(i[2:])
for i in mysql_config('cflags')
if i.startswith(compiler_flag('I')) ]
if static:
extra_objects.append(os.path.join(
library_dirs[0],'lib%s.a' % client))
define_macros = [
('version_info', metadata['version_info']),
('__version__', metadata['version']),
]
rel = open("MySQLdb/release.py",'w')
rel.write("""
__author__ = "%(author)s <%(author_email)s>"
version_info = %(version_info)s
__version__ = "%(version)s"
""" % metadata)
rel.close()
del metadata['version_info']
ext_mysql_metadata = dict(
name="_mysql",
define_macros=define_macros,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_objects=extra_objects,
sources=['_mysql.c'],
)
if config.read(['site.cfg']):
ext_mysql_metadata.update([ (k, v.split()) for k, v in config.items('compiler') ])
ext_mysql = Extension(**ext_mysql_metadata)
metadata['ext_modules'] = [ext_mysql]
setup(**metadata)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks