annotate setup.py @ 4:b5a377255eea MySQLdb

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