-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·280 lines (239 loc) · 8.77 KB
/
setup.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python
#
# setup.py
#
# Copyright (C) 2009 Damien Churchill <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import os
import sys
import getpass
sys.path.append(os.path.join(os.path.dirname(__file__), '.pyrex'))
try:
from setuptools import setup, Extension
except ImportError:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, Extension
from distutils import log
from distutils.cmd import Command
from distutils.command.clean import clean as _clean
from Cython.Distutils import build_ext as _build_ext
_extra_compile_args = [
'-DMSDBLIB'
]
ROOT = os.path.dirname(__file__)
WINDOWS = False
if sys.platform == 'win32':
WINDOWS = True
WIN32 = os.path.join(ROOT, 'win32')
FREETDS = os.path.join(WIN32, 'freetds')
include_dirs = [os.path.join(FREETDS, 'include')]
library_dirs = [os.path.join(FREETDS, 'lib')]
libraries = [
'libiconv',
'iconv',
'sybdb',
'ws2_32',
'wsock32',
'kernel32',
]
_extra_compile_args.append('-Wl,-allow-multiple-definition')
_extra_compile_args.append('-Wl,-subsystem,windows-mthreads')
_extra_compile_args.append('-mwindows')
_extra_compile_args.append('-Wl,--strip-all')
else:
include_dirs = [
'/usr/local/include', '/usr/local/include/freetds', # first local install
'/usr/include', '/usr/include/freetds', # some generic Linux paths
'/usr/include/freetds_mssql', # some versions of Mandriva
'/usr/local/freetds/include', # FreeBSD
'/usr/pkg/freetds/include' # NetBSD
]
library_dirs = [
'/usr/local/lib', '/usr/local/lib/freetds',
'/usr/lib64',
'/usr/lib', '/usr/lib/freetds',
'/usr/lib/freetds_mssql',
'/usr/local/freetds/lib',
'/usr/pkg/freetds/lib'
]
libraries = [ "sybdb" ] # on Mandriva you may have to change it to sybdb_mssql
if sys.platform == 'darwin':
fink = '/sw/'
include_dirs.insert(0, fink + 'include')
library_dirs.insert(0, fink + 'lib')
# some mac ports paths
include_dirs += [
'/opt/local/include',
'/opt/local/include/freetds',
'/opt/local/freetds/include'
]
library_dirs += [
'/opt/local/lib',
'/opt/local/lib/freetds',
'/opt/local/freetds/lib'
]
class build_ext(_build_ext):
"""
Subclass the Cython build_ext command so it extracts freetds.zip if it
hasn't already been done.
"""
def run(self):
# Not running on windows means we don't want to do this
if not WINDOWS:
return _build_ext.run(self)
if os.path.isdir(FREETDS):
return _build_ext.run(self)
log.info('extracting FreeTDS')
from zipfile import ZipFile
zip_file = ZipFile(os.path.join(WIN32, 'freetds.zip'))
for name in zip_file.namelist():
dest = os.path.normpath(os.path.join(WIN32, name))
if name.endswith('/'):
os.makedirs(dest)
else:
f = open(dest, 'wb')
f.write(zip_file.read(name))
f.close()
zip_file.close()
return _build_ext.run(self)
class clean(_clean):
"""
Subclass clean so it removes all the Cython generated C files.
"""
def run(self):
_clean.run(self)
for ext in self.distribution.ext_modules:
cy_sources = [s for s in ext.sources if s.endswith('.pyx')]
for cy_source in cy_sources:
c_source = cy_source[:-3] + 'c'
if os.path.exists(c_source):
log.info('removing %s', c_source)
os.remove(c_source)
# Check if we need to remove the freetds directory
if WINDOWS:
# If the directory exists, remove it
if os.path.isdir(FREETDS):
import shutil
shutil.rmtree(FREETDS)
class release(Command):
"""
Setuptools command to run all the required commands to perform
a release. This acts differently depending on the platform it
is being run on.
"""
description = "Run all the commands required for a release."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.username = None
self.password = None
self.store = None
if WINDOWS:
self.release_windows()
else:
self.release_unix()
def release_windows(self):
# generate windows source distributions
sdist = self.distribution.get_command_obj('sdist')
sdist.formats = 'zip'
sdist.ensure_finalized()
sdist.run()
# generate a windows egg
self.run_command('bdist_egg')
# generate windows installers
bdist = self.reinitialize_command('bdist')
bdist.formats = 'zip,wininst'
bdist.ensure_finalized()
bdist.run()
(name, version, fullname) = self.get_info()
self.upload(fullname + '.zip', '%s %s source zipped' % (name, version))
self.upload(fullname + '.win32.zip', '%s %s win32 zip installer' % (name, version))
self.upload(fullname + '.win32-py2.6.exe', '%s %s windows installer' % (name, version))
self.upload(fullname + '-py2.6-win32.egg', '%s %s windows egg' % (name, version))
def release_unix(self):
# generate linux source distributions
sdist = self.distribution.get_command_obj('sdist')
sdist.formats = 'gztar,bztar'
sdist.ensure_finalized()
sdist.run()
(name, version, fullname) = self.get_info()
self.upload(fullname + '.tar.gz', '%s %s source gzipped' % (name, version))
self.upload(fullname + '.tar.bz2', '%s %s source bzipped' % (name, version))
def get_info(self):
"""
Return the project name and version
"""
return (
self.distribution.get_name(),
self.distribution.get_version(),
self.distribution.get_fullname()
)
def upload(self, filename, comment):
from gc_upload import upload
if self.username is None:
username = raw_input('Username: ')
password = getpass.getpass('Password: ')
if self.store is None:
store = raw_input('Store credentials for later use? [Y/n]')
self.store = store in ('', 'y', 'Y')
if self.store:
self.username = username
self.password = password
else:
username = self.username
password = self.password
filename = os.path.join('dist', filename)
log.info('uploading %s to googlecode', filename)
(status, reason, url) = upload(filename, 'pymssql', username, password, comment)
if not url:
log.error('upload to googlecode failed: %s', reason)
setup(
name = 'pymssql',
version = '1.9.909',
description = 'A simple database interface to MS-SQL for Python.',
long_description = 'A simple database interface to MS-SQL for Python.',
author = 'Damien Churchill',
author_email = '[email protected]',
license = 'LGPL',
url = 'http://pymssql.sourceforge.net',
cmdclass = {
'build_ext': build_ext,
'clean': clean,
'release': release
},
data_files = [
('', ['_mssql.pyx', 'pymssql.pyx'])
],
zip_safe = False,
setup_requires=["Cython>=0.13.1"],
ext_modules = [Extension('_mssql', ['_mssql.pyx'],
extra_compile_args = _extra_compile_args,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries),
Extension('pymssql', ['pymssql.pyx'],
extra_compile_args = _extra_compile_args,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries)]
)