Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 277 lines (199 sloc) 9.571 kb
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
1 #!/usr/bin/python
2
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
3 import sys, os, re, platform
eb54575 @mkleehammer Issue 80: setup.py uses setuptools if available to allow building eggs
authored
4 from os.path import exists, abspath, dirname, join, isdir
5
6 try:
7 # Allow use of setuptools so eggs can be built.
b4cf762 @mkleehammer Issue 167: Import of setuptools incorrect
authored
8 from setuptools import setup, Command
eb54575 @mkleehammer Issue 80: setup.py uses setuptools if available to allow building eggs
authored
9 except ImportError:
10 from distutils.core import setup, Command
11
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
12 from distutils.extension import Extension
13 from distutils.errors import *
14
15 OFFICIAL_BUILD = 9999
16
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
17 def _print(s):
18 # Python 2/3 compatibility
19 sys.stdout.write(s + '\n')
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
20
e82cb43 Added version command to setup.py
Michael Kleehammer authored
21 class VersionCommand(Command):
f89886e @mkleehammer Added description to setup version command
authored
22
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
23 description = "prints the pyodbc version, determined from git"
f89886e @mkleehammer Added description to setup version command
authored
24
e82cb43 Added version command to setup.py
Michael Kleehammer authored
25 user_options = []
26
27 def initialize_options(self):
28 self.verbose = 0
29
30 def finalize_options(self):
31 pass
32
33 def run(self):
34 version_str, version = get_version()
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
35 sys.stdout.write(version_str + '\n')
e82cb43 Added version command to setup.py
Michael Kleehammer authored
36
37
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
38 class TagsCommand(Command):
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
39
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
40 description = 'runs etags'
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
41
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
42 user_options = []
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
43
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
44 def initialize_options(self):
45 pass
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
46
a42975a @mkleehammer Ported setup tags command from v31 branch.
authored
47 def finalize_options(self):
48 pass
49
50 def run(self):
51 # Windows versions of etag do not seem to expand wildcards (which Unix shells normally do for Unix utilities),
52 # so find all of the files ourselves.
53 files = [ join('src', f) for f in os.listdir('src') if f.endswith(('.h', '.cpp')) ]
54 cmd = 'etags %s' % ' '.join(files)
55 return os.system(cmd)
56
57
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
58
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
59 def main():
60
61 version_str, version = get_version()
62
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
63 settings = get_compiler_settings(version_str)
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches conne…
authored
64
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
65 files = [ abspath(join('src', f)) for f in os.listdir('src') if f.endswith('.cpp') ]
523aed0 @mkleehammer Issue 91: decimal fix; Completely reworked parameters; added leakcheck
authored
66
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
67 if exists('MANIFEST'):
68 os.remove('MANIFEST')
69
6a457c3 @mkleehammer Issue 227: Fix Python 2.5 compatability
authored
70 kwargs = {
71 'name': "pyodbc",
72 'version': version_str,
73 'description': "DB API Module for ODBC",
74
75 'long_description': ('A Python DB API 2 module for ODBC. This project provides an up-to-date, '
76 'convenient interface to ODBC using native data types like datetime and decimal.'),
77
78 'maintainer': "Michael Kleehammer",
79 'maintainer_email': "michael@kleehammer.com",
80
81 'ext_modules': [Extension('pyodbc', files, **settings)],
82
83 'license': 'MIT',
84
85 'classifiers': ['Development Status :: 5 - Production/Stable',
86 'Intended Audience :: Developers',
87 'Intended Audience :: System Administrators',
88 'License :: OSI Approved :: MIT License',
89 'Operating System :: Microsoft :: Windows',
90 'Operating System :: POSIX',
91 'Programming Language :: Python',
92 'Programming Language :: Python :: 2',
93 'Programming Language :: Python :: 3',
94 'Topic :: Database',
95 ],
96
97 'url': 'http://code.google.com/p/pyodbc',
98 'download_url': 'http://code.google.com/p/pyodbc/downloads/list',
99 'cmdclass': { 'version' : VersionCommand,
100 'tags' : TagsCommand }
101 }
102
9b7799f @mkleehammer Issue 182: Installer crash on Windows 7 due to UAC
authored
103 if sys.hexversion >= 0x02060000:
6a457c3 @mkleehammer Issue 227: Fix Python 2.5 compatability
authored
104 kwargs['options'] = {
105 'bdist_wininst': {'user_access_control' : 'auto'}
106 }
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
107
6a457c3 @mkleehammer Issue 227: Fix Python 2.5 compatability
authored
108 setup(**kwargs)
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
109
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches conne…
authored
110
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
111 def get_compiler_settings(version_str):
112
113 settings = { 'libraries': [],
114 'define_macros' : [ ('PYODBC_VERSION', version_str) ] }
115
116 # This isn't the best or right way to do this, but I don't see how someone is supposed to sanely subclass the build
117 # command.
118 for option in ['assert', 'trace', 'leak-check']:
119 try:
120 sys.argv.remove('--%s' % option)
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
121 settings['define_macros'].append(('PYODBC_%s' % option.replace('-', '_').upper(), 1))
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
122 except ValueError:
123 pass
124
125 if os.name == 'nt':
3c7a9e7 @mkleehammer Cleaned up compiler warnings
authored
126 settings['extra_compile_args'] = ['/Wall',
127 '/wd4668',
128 '/wd4820',
129 '/wd4711', # function selected for automatic inline expansion
130 '/wd4100', # unreferenced formal parameter
131 '/wd4127', # "conditional expression is constant" testing compilation constants
b2dfac9 @mkleehammer Issue 178: Fixed compilation issues with 4.6.2
authored
132 '/wd4191', # casts to PYCFunction which doesn't have the keywords parameter
3c7a9e7 @mkleehammer Cleaned up compiler warnings
authored
133 ]
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
134 settings['libraries'].append('odbc32')
eeede2f @mkleehammer Added pyodbc.drivers() for Windows builds.
authored
135 settings['libraries'].append('advapi32')
9dd144f @mkleehammer Added pyodbc.conf for preprocessor-time access to sizeof(SQLWCHAR)
authored
136
137 elif os.environ.get("OS", '').lower().startswith('windows'):
138 # Windows Cygwin (posix on windows)
139 # OS name not windows, but still on Windows
140 settings['libraries'].append('odbc32')
141
142 elif sys.platform == 'darwin':
143 # OS/X now ships with iODBC.
144 settings['libraries'].append('iodbc')
145
146 else:
147 # Other posix-like: Linux, Solaris, etc.
148
149 # Python functions take a lot of 'char *' that really should be const. gcc complains about this *a lot*
150 settings['extra_compile_args'] = ['-Wno-write-strings']
151
152 # What is the proper way to detect iODBC, MyODBC, unixODBC, etc.?
153 settings['libraries'].append('odbc')
154
155 return settings
156
157
158 def add_to_path():
159 """
160 Prepends the build directory to the path so pyodbcconf can be imported without installing it.
161 """
162 # Now run the utility
163
164 import imp
165 library_exts = [ t[0] for t in imp.get_suffixes() if t[-1] == imp.C_EXTENSION ]
166 library_names = [ 'pyodbcconf%s' % ext for ext in library_exts ]
167
168 # Only go into directories that match our version number.
169
170 dir_suffix = '-%s.%s' % (sys.version_info[0], sys.version_info[1])
171
172 build = join(dirname(abspath(__file__)), 'build')
173
174 for top, dirs, files in os.walk(build):
175 dirs = [ d for d in dirs if d.endswith(dir_suffix) ]
176 for name in library_names:
177 if name in files:
178 sys.path.insert(0, top)
179 return
180
181 raise SystemExit('Did not find pyodbcconf')
182
183
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
184 def get_version():
185 """
186 Returns the version of the product as (description, [major,minor,micro,beta]).
187
188 If the release is official, `beta` will be 9999 (OFFICIAL_BUILD).
189
190 1. If in a git repository, use the latest tag (git describe).
191 2. If in an unzipped source directory (from setup.py sdist),
192 read the version from the PKG-INFO file.
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
193 3. Use 3.0.0.0 and complain a lot.
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
194 """
195 # My goal is to (1) provide accurate tags for official releases but (2) not have to manage tags for every test
196 # release.
197 #
198 # Official versions are tagged using 3 numbers: major, minor, micro. A build of a tagged version should produce
199 # the version using just these pieces, such as 2.1.4.
200 #
201 # Unofficial versions are "working towards" the next version. So the next unofficial build after 2.1.4 would be a
202 # beta for 2.1.5. Using 'git describe' we can find out how many changes have been made after 2.1.4 and we'll use
203 # this count as the beta id (beta1, beta2, etc.)
204 #
c8c8fe1 fixed pyodbc.version for non-beta releases
Michael Kleehammer authored
205 # Since the 4 numbers are put into the Windows DLL, we want to make sure the beta versions sort *before* the
206 # official, so we set the official build number to 9999, but we don't show it.
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
207
208 name = None # branch/feature name. Should be None for official builds.
209 numbers = None # The 4 integers that make up the version.
210
211 # If this is a source release the version will have already been assigned and be in the PKG-INFO file.
212
213 name, numbers = _get_version_pkginfo()
214
215 # If not a source release, we should be in a git repository. Look for the latest tag.
216
217 if not numbers:
218 name, numbers = _get_version_git()
219
220 if not numbers:
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
221 _print('WARNING: Unable to determine version. Using 3.0.0.0')
222 name, numbers = '3.0.0-unsupported', [3,0,0,0]
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
223
224 return name, numbers
225
226
227 def _get_version_pkginfo():
228 filename = join(dirname(abspath(__file__)), 'PKG-INFO')
229 if exists(filename):
230 re_ver = re.compile(r'^Version: \s+ (\d+)\.(\d+)\.(\d+) (?: -beta(\d+))?', re.VERBOSE)
231 for line in open(filename):
232 match = re_ver.search(line)
233 if match:
234 name = line.split(':', 1)[1].strip()
9ff5342 @mkleehammer Issue 95: "beta0" added when building from source distribution.
authored
235 numbers = [int(n or 0) for n in match.groups()[:3]]
236 numbers.append(int(match.group(4) or OFFICIAL_BUILD)) # don't use 0 as a default for build
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
237 return name, numbers
238
239 return None, None
240
241
242 def _get_version_git():
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
243 n, result = getoutput('git describe --tags --match 3.*')
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
244 if n:
c278e74 @mkleehammer Single source base for Python 2 and 3
authored
245 _print('WARNING: git describe failed with: %s %s' % (n, result))
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
246 return None, None
247
248 match = re.match(r'(\d+).(\d+).(\d+) (?: -(\d+)-g[0-9a-z]+)?', result, re.VERBOSE)
249 if not match:
250 return None, None
251
1567234 eliminate gcc write-strings warnings; caused by Python declarations -…
Michael Kleehammer authored
252 numbers = [int(n or OFFICIAL_BUILD) for n in match.groups()]
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
253 if numbers[-1] == OFFICIAL_BUILD:
254 name = '%s.%s.%s' % tuple(numbers[:3])
255 if numbers[-1] != OFFICIAL_BUILD:
256 # This is a beta of the next micro release, so increment the micro number to reflect this.
257 numbers[-2] += 1
691b6ba @mkleehammer Reworked Unicode; changed version format; more Py_ssize_t
authored
258 name = '%s.%s.%s-beta%02d' % tuple(numbers)
259
260 n, result = getoutput('git branch')
261 branch = re.search(r'\* (\w+)', result).group(1)
262 if branch != 'master' and not re.match('^v\d+$', branch):
263 name = branch + '-' + name
264
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
265 return name, numbers
266
267
268
269 def getoutput(cmd):
270 pipe = os.popen(cmd, 'r')
271 text = pipe.read().rstrip('\n')
272 status = pipe.close() or 0
273 return status, text
274
275 if __name__ == '__main__':
276 main()
Something went wrong with that request. Please try again.