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