Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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