forked from mongodb/mongo-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
executable file
·197 lines (166 loc) · 6.21 KB
/
setup.py
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
#!/usr/bin/env python
import sys
import os
try:
import subprocess
has_subprocess = True
except:
has_subprocess = False
import shutil
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup
from setuptools import Feature
from distutils.cmd import Command
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError
from distutils.errors import DistutilsPlatformError, DistutilsExecError
from distutils.core import Extension
# Remember to change in pymongo/__init__.py as well!
version = "1.11+"
f = open("README.rst")
try:
try:
readme_content = f.read()
except:
readme_content = ""
finally:
f.close()
class doc(Command):
description = "generate or test documentation"
user_options = [("test", "t",
"run doctests instead of generating documentation")]
boolean_options = ["test"]
def initialize_options(self):
self.test = False
def finalize_options(self):
pass
def run(self):
if self.test:
path = "doc/_build/doctest"
mode = "doctest"
else:
path = "doc/_build/%s" % version
mode = "html"
# shutil.rmtree("doc/_build", ignore_errors=True)
try:
os.makedirs(path)
except:
pass
if has_subprocess:
status = subprocess.call(["sphinx-build", "-E", "-b", mode, "doc", path])
if status:
raise RuntimeError("documentation step '%s' failed" % mode)
print ""
print "Documentation step '%s' performed, results here:" % mode
print " %s/" % path
else:
print """
`setup.py doc` is not supported for this version of Python.
Please ask in the user forums for help.
"""
if sys.platform == 'win32' and sys.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)
class custom_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.
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. Python development package names for popular
Linux distributions include:
RHEL/CentOS: python-devel
Debian/Ubuntu: python-dev
%s
**************************************************************
"""
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError, e:
print e
print self.warning_message % ("Extension modules",
"There was an issue with your "
"platform configuration "
"- see above.")
def build_extension(self, ext):
if sys.version_info[:3] >= (2, 4, 0):
try:
build_ext.build_extension(self, ext)
except build_errors, e:
print e
print self.warning_message % ("The %s extension "
"module" % ext.name,
"Above is the ouput showing how "
"the compilation failed.")
else:
print self.warning_message % ("The %s extension module" % ext.name,
"Please use Python >= 2.4 to take "
"advantage of the extension.")
c_ext = Feature(
"optional C extensions",
standard=True,
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/_cbsonmodule.c',
'bson/time64.c',
'bson/buffer.c',
'bson/encoding_helpers.c'])])
if "--no_ext" in sys.argv:
sys.argv = [x for x in sys.argv if x != "--no_ext"]
features = {}
elif sys.byteorder == "big":
print """
*****************************************************
The optional C extensions are currently not supported
on big endian platforms and will not be built.
Performance may be degraded.
*****************************************************
"""
features = {}
else:
features = {"c-ext": c_ext}
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@10gen.com",
url="http://github.com/mongodb/mongo-python-driver",
keywords=["mongo", "mongodb", "pymongo", "gridfs", "bson"],
packages=["bson", "pymongo", "gridfs"],
install_requires=[],
features=features,
license="Apache License, Version 2.0",
test_suite="nose.collector",
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",
"Topic :: Database"],
cmdclass={"build_ext": custom_build_ext,
"doc": doc})