forked from mongodb/mongo-python-driver
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
executable file
·309 lines (260 loc) · 11 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·309 lines (260 loc) · 11 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
importos
importplatform
importre
importsubprocess
importsys
importwarnings
# Hack to silence atexit traceback in some Python versions
try:
importmultiprocessing
exceptImportError:
pass
# Don't force people to install setuptools unless
# we have to.
try:
fromsetuptoolsimportsetup
exceptImportError:
fromez_setupimportuse_setuptools
use_setuptools()
fromsetuptoolsimportsetup
fromdistutils.cmdimportCommand
fromdistutils.command.build_extimportbuild_ext
fromdistutils.errorsimportCCompilerError, DistutilsOptionError
fromdistutils.errorsimportDistutilsPlatformError, DistutilsExecError
fromdistutils.coreimportExtension
version="3.1.0.dev0"
f=open("README.rst")
try:
try:
readme_content=f.read()
except:
readme_content=""
finally:
f.close()
# PYTHON-654 - Clang doesn't support -mno-fused-madd but the pythons Apple
# ships are built with it. This is a problem starting with Xcode 5.1
# since clang 3.4 errors out when it encounters unrecognized compiler
# flags. This hack removes -mno-fused-madd from the CFLAGS automatically
# generated by distutils for Apple provided pythons, allowing C extension
# builds to complete without error. The inspiration comes from older
# versions of distutils.sysconfig.get_config_vars.
ifsys.platform=='darwin'and'clang'inplatform.python_compiler().lower():
fromdistutils.sysconfigimportget_config_vars
res=get_config_vars()
forkeyin ('CFLAGS', 'PY_CFLAGS'):
ifkeyinres:
flags=res[key]
flags=re.sub('-mno-fused-madd', '', flags)
res[key] =flags
classtest(Command):
description="run the tests"
user_options= [
("test-module=", "m", "Discover tests in specified module"),
("test-suite=", "s",
"Test suite to run (e.g. 'some_module.test_suite')"),
("failfast", "f", "Stop running tests on first failure or error")
]
definitialize_options(self):
self.test_module=None
self.test_suite=None
self.failfast=False
deffinalize_options(self):
ifself.test_suiteisNoneandself.test_moduleisNone:
self.test_module='test'
elifself.test_moduleisnotNoneandself.test_suiteisnotNone:
raiseDistutilsOptionError(
"You may specify a module or suite, but not both"
)
defrun(self):
# Installing required packages, running egg_info and build_ext are
# part of normal operation for setuptools.command.test.test
ifself.distribution.install_requires:
self.distribution.fetch_build_eggs(
self.distribution.install_requires)
ifself.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
self.run_command('egg_info')
build_ext_cmd=self.reinitialize_command('build_ext')
build_ext_cmd.inplace=1
self.run_command('build_ext')
# Construct a TextTestRunner directly from the unittest imported from
# test (this will be unittest2 under Python 2.6), which creates a
# TestResult that supports the 'addSkip' method. setuptools will by
# default create a TextTestRunner that uses the old TestResult class,
# resulting in DeprecationWarnings instead of skipping tests under 2.6.
fromtestimportunittest, PymongoTestRunner, test_cases
ifself.test_suiteisNone:
all_tests=unittest.defaultTestLoader.discover(self.test_module)
suite=unittest.TestSuite()
suite.addTests(sorted(test_cases(all_tests),
key=lambdax: x.__module__))
else:
suite=unittest.defaultTestLoader.loadTestsFromName(
self.test_suite)
result=PymongoTestRunner(verbosity=2,
failfast=self.failfast).run(suite)
sys.exit(notresult.wasSuccessful())
classdoc(Command):
description="generate or test documentation"
user_options= [("test", "t",
"run doctests instead of generating documentation")]
boolean_options= ["test"]
definitialize_options(self):
self.test=False
deffinalize_options(self):
pass
defrun(self):
ifself.test:
path="doc/_build/doctest"
mode="doctest"
else:
path="doc/_build/%s"%version
mode="html"
try:
os.makedirs(path)
except:
pass
status=subprocess.call(["sphinx-build", "-E",
"-b", mode, "doc", path])
ifstatus:
raiseRuntimeError("documentation step '%s' failed"% (mode,))
sys.stdout.write("\nDocumentation step '%s' performed, results here:\n"
" %s/\n"% (mode, path))
ifsys.platform=='win32'andsys.version_info> (2, 6):
# 2.6's distutils.msvc9compiler can raise an IOError when failing to
# find the compiler
build_errors= (CCompilerError, DistutilsExecError,
DistutilsPlatformError, IOError)
else:
build_errors= (CCompilerError, DistutilsExecError, DistutilsPlatformError)
classcustom_build_ext(build_ext):
"""Allow C extension building to fail.
The C extension speeds up BSON encoding, but is not essential.
"""
warning_message="""
********************************************************************
WARNING: %s could not
be compiled. No C extensions are essential for PyMongo to run,
although they do result in significant speed improvements.
%s
Please see the installation docs for solutions to build issues:
http://api.mongodb.org/python/current/installation.html
Here are some hints for popular operating systems:
If you are seeing this message on Linux you probably need to
install GCC and/or the Python development package for your
version of Python.
Debian and Ubuntu users should issue the following command:
$ sudo apt-get install build-essential python-dev
Users of Red Hat based distributions (RHEL, CentOS, Amazon Linux,
Oracle Linux, Fedora, etc.) should issue the following command:
$ sudo yum install gcc python-devel
If you are seeing this message on Microsoft Windows please install
PyMongo using the MS Windows installer for your version of Python,
available on pypi here:
http://pypi.python.org/pypi/pymongo/#downloads
If you are seeing this message on OSX please read the documentation
here:
http://api.mongodb.org/python/current/installation.html#osx
********************************************************************
"""
defrun(self):
try:
build_ext.run(self)
exceptDistutilsPlatformError:
e=sys.exc_info()[1]
sys.stdout.write('%s\n'%str(e))
warnings.warn(self.warning_message% ("Extension modules",
"There was an issue with "
"your platform configuration"
" - see above."))
defbuild_extension(self, ext):
name=ext.name
ifsys.version_info[:3] >= (2, 6, 0):
try:
build_ext.build_extension(self, ext)
exceptbuild_errors:
e=sys.exc_info()[1]
sys.stdout.write('%s\n'%str(e))
warnings.warn(self.warning_message% ("The %s extension "
"module"% (name,),
"The output above "
"this warning shows how "
"the compilation "
"failed."))
else:
warnings.warn(self.warning_message% ("The %s extension "
"module"% (name,),
"Please use Python >= 2.6 "
"to take advantage of the "
"extension."))
ext_modules= [Extension('bson._cbson',
include_dirs=['bson'],
sources=['bson/_cbsonmodule.c',
'bson/time64.c',
'bson/buffer.c',
'bson/encoding_helpers.c']),
Extension('pymongo._cmessage',
include_dirs=['bson'],
sources=['pymongo/_cmessagemodule.c',
'bson/buffer.c'])]
extra_opts= {
"packages": ["bson", "pymongo", "gridfs"]
}
ifsys.version_info[:2] == (2, 6):
extra_opts['tests_require'] ="unittest2"
if"--no_ext"insys.argv:
sys.argv.remove("--no_ext")
elif (sys.platform.startswith("java") or
sys.platform=="cli"or
"PyPy"insys.version):
sys.stdout.write("""
*****************************************************\n
The optional C extensions are currently not supported\n
by this python implementation.\n
*****************************************************\n
""")
elifsys.byteorder=="big":
sys.stdout.write("""
*****************************************************\n
The optional C extensions are currently not supported\n
on big endian platforms and will not be built.\n
Performance may be degraded.\n
*****************************************************\n
""")
else:
extra_opts['ext_modules'] =ext_modules
setup(
name="pymongo",
version=version,
description="Python driver for MongoDB <http://www.mongodb.org>",
long_description=readme_content,
author="Mike Dirolf",
author_email="mongodb-user@googlegroups.com",
maintainer="Bernie Hackett",
maintainer_email="bernie@mongodb.com",
url="http://github.com/mongodb/mongo-python-driver",
keywords=["mongo", "mongodb", "pymongo", "gridfs", "bson"],
install_requires=[],
license="Apache License, Version 2.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Database"],
cmdclass={"build_ext": custom_build_ext,
"doc": doc,
"test": test},
**extra_opts
)