Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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