Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 185 lines (138 sloc) 6.639 kb
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
1 #!/usr/bin/python
2
3 import sys, os, re
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches connecti...
authored
4 from distutils.core import setup
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
5 from distutils.extension import Extension
6 from distutils.errors import *
7 from os.path import exists, abspath, dirname, join, isdir
8
9 OFFICIAL_BUILD = 9999
10
11 def main():
12
13 version_str, version = get_version()
14
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches connecti...
authored
15 files = [ abspath(join('src', f)) for f in os.listdir('src') if f.endswith('.cpp') ]
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
16 libraries = []
17
18 extra_compile_args = None
19 extra_link_args = None
20
21 if os.name == 'nt':
22 # Windows native
23 files.append(join('src', 'pyodbc.rc'))
24 libraries.append('odbc32')
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
25 extra_compile_args = ['/W4']
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
26
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
27 # extra_compile_args = ['/W4', '/Zi', '/Od']
28 # extra_link_args = ['/DEBUG']
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
29
30 elif os.environ.get("OS", '').lower().startswith('windows'):
31 # Windows Cygwin (posix on windows)
32 # OS name not windows, but still on Windows
33 libraries.append('odbc32')
34
35 elif sys.platform == 'darwin':
36 # OS/X now ships with iODBC.
37 libraries.append('iodbc')
38
39 else:
40 # Other posix-like: Linux, Solaris, etc.
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
41
42 # Python functions take a lot of 'char *' that really should be const. gcc complains about this *a lot*
43 extra_compile_args = ['-Wno-write-strings']
44
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
45 # What is the proper way to detect iODBC, MyODBC, unixODBC, etc.?
46 libraries.append('odbc')
47
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
48 macros = [('PYODBC_%s' % name, value) for name,value in zip(['MAJOR', 'MINOR', 'MICRO', 'BUILD'], version)]
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches connecti...
authored
49
50 # 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
51 # command.
52 try:
53 sys.argv.remove('--assert')
54 macros.append(('PYODBC_ASSERT', 1))
55 except ValueError:
56 pass
57
58 try:
59 sys.argv.remove('--trace')
60 macros.append(('TRACE_ALL', 1))
61 except ValueError:
62 pass
63
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
64 if exists('MANIFEST'):
65 os.remove('MANIFEST')
66
67 setup (name = "pyodbc",
68 version = version_str,
69 description = "DB API Module for ODBC",
70
71 long_description = ('A Python DB API 2 module for ODBC. This project provides an up-to-date, '
72 'convenient interface to ODBC using native data types like datetime and decimal.'),
73
74 maintainer = "Michael Kleehammer",
75 maintainer_email = "michael@kleehammer.com",
76
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
77 ext_modules = [Extension('pyodbc', files,
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
78 libraries=libraries,
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches connecti...
authored
79 define_macros = macros,
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
80 extra_compile_args=extra_compile_args,
81 extra_link_args=extra_link_args
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
82 )],
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
83
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
84 classifiers = ['Development Status :: 5 - Production/Stable',
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
85 'Intended Audience :: Developers',
86 'Intended Audience :: System Administrators',
87 'License :: OSI Approved :: MIT License',
88 'Operating System :: Microsoft :: Windows',
89 'Operating System :: POSIX',
90 'Programming Language :: Python',
91 'Topic :: Database',
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
92 ],
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
93
94 url = 'http://pyodbc.sourceforge.net',
95 download_url = 'http://github.com/pyodbc/pyodbc/tree/master')
96
97
04d8111 @mkleehammer Added SQL Server 2008 date/time extensions support. Now caches connecti...
authored
98
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
99 def get_version():
100 """
101 Returns the version of the product as (description, [major,minor,micro,beta]).
102
103 If the release is official, `beta` will be 9999 (OFFICIAL_BUILD).
104
105 1. If in a git repository, use the latest tag (git describe).
106 2. If in an unzipped source directory (from setup.py sdist),
107 read the version from the PKG-INFO file.
108 3. Use 2.1.0.0 and complain a lot.
109 """
110 # My goal is to (1) provide accurate tags for official releases but (2) not have to manage tags for every test
111 # release.
112 #
113 # Official versions are tagged using 3 numbers: major, minor, micro. A build of a tagged version should produce
114 # the version using just these pieces, such as 2.1.4.
115 #
116 # Unofficial versions are "working towards" the next version. So the next unofficial build after 2.1.4 would be a
117 # 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
118 # this count as the beta id (beta1, beta2, etc.)
119 #
c8c8fe1 fixed pyodbc.version for non-beta releases
Michael Kleehammer authored
120 # Since the 4 numbers are put into the Windows DLL, we want to make sure the beta versions sort *before* the
121 # 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
122
123 name = None # branch/feature name. Should be None for official builds.
124 numbers = None # The 4 integers that make up the version.
125
126 # If this is a source release the version will have already been assigned and be in the PKG-INFO file.
127
128 name, numbers = _get_version_pkginfo()
129
130 # If not a source release, we should be in a git repository. Look for the latest tag.
131
132 if not numbers:
133 name, numbers = _get_version_git()
134
135 if not numbers:
136 print 'WARNING: Unable to determine version. Using 2.1.0.0'
137 name, numbers = '2.1.0-unsupported', [2,1,0,0]
138
139 return name, numbers
140
141
142 def _get_version_pkginfo():
143 filename = join(dirname(abspath(__file__)), 'PKG-INFO')
144 if exists(filename):
145 re_ver = re.compile(r'^Version: \s+ (\d+)\.(\d+)\.(\d+) (?: -beta(\d+))?', re.VERBOSE)
146 for line in open(filename):
147 match = re_ver.search(line)
148 if match:
149 name = line.split(':', 1)[1].strip()
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
150 numbers = [int(n or 0) for n in match.groups()]
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
151 return name, numbers
152
153 return None, None
154
155
156 def _get_version_git():
157 n, result = getoutput('git describe --tags')
158 if n:
159 print 'WARNING: git describe failed with: %s %s' % (n, result)
160 return None, None
161
162 match = re.match(r'(\d+).(\d+).(\d+) (?: -(\d+)-g[0-9a-z]+)?', result, re.VERBOSE)
163 if not match:
164 return None, None
165
1567234 eliminate gcc write-strings warnings; caused by Python declarations - no...
Michael Kleehammer authored
166 numbers = [int(n or OFFICIAL_BUILD) for n in match.groups()]
c3f6b46 @mkleehammer Import from Subversion 2.0.63; reworked versioning
authored
167 if numbers[-1] == OFFICIAL_BUILD:
168 name = '%s.%s.%s' % tuple(numbers[:3])
169 if numbers[-1] != OFFICIAL_BUILD:
170 # This is a beta of the next micro release, so increment the micro number to reflect this.
171 numbers[-2] += 1
172 name = '%s.%s.%s-beta%s' % tuple(numbers)
173 return name, numbers
174
175
176
177 def getoutput(cmd):
178 pipe = os.popen(cmd, 'r')
179 text = pipe.read().rstrip('\n')
180 status = pipe.close() or 0
181 return status, text
182
183 if __name__ == '__main__':
184 main()
Something went wrong with that request. Please try again.