PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/setup.py

https://github.com/linuxnow/mongo-python-driver
Python | 207 lines | 202 code | 4 blank | 1 comment | 6 complexity | 3c6c5f943bab9eb9ea2cb71d43363de8 MD5 | raw file
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. try:
  5. import subprocess
  6. has_subprocess = True
  7. except:
  8. has_subprocess = False
  9. import shutil
  10. from ez_setup import use_setuptools
  11. use_setuptools()
  12. from setuptools import setup
  13. from setuptools import Feature
  14. from distutils.cmd import Command
  15. from distutils.command.build_ext import build_ext
  16. from distutils.errors import CCompilerError
  17. from distutils.errors import DistutilsPlatformError, DistutilsExecError
  18. from distutils.core import Extension
  19. from pymongo import version
  20. f = open("README.rst")
  21. try:
  22. try:
  23. readme_content = f.read()
  24. except:
  25. readme_content = ""
  26. finally:
  27. f.close()
  28. class doc(Command):
  29. description = "generate or test documentation"
  30. user_options = [("test", "t",
  31. "run doctests instead of generating documentation")]
  32. boolean_options = ["test"]
  33. def initialize_options(self):
  34. self.test = False
  35. def finalize_options(self):
  36. pass
  37. def run(self):
  38. if self.test:
  39. path = "doc/_build/doctest"
  40. mode = "doctest"
  41. else:
  42. path = "doc/_build/%s" % version
  43. mode = "html"
  44. # shutil.rmtree("doc/_build", ignore_errors=True)
  45. try:
  46. os.makedirs(path)
  47. except:
  48. pass
  49. if has_subprocess:
  50. status = subprocess.call(["sphinx-build", "-E", "-b", mode, "doc", path])
  51. if status:
  52. raise RuntimeError("documentation step '%s' failed" % mode)
  53. print ""
  54. print "Documentation step '%s' performed, results here:" % mode
  55. print " %s/" % path
  56. else:
  57. print """
  58. `setup.py doc` is not supported for this version of Python.
  59. Please ask in the user forums for help.
  60. """
  61. if sys.platform == 'win32' and sys.version_info > (2, 6):
  62. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  63. # find the compiler
  64. build_errors = (CCompilerError, DistutilsExecError,
  65. DistutilsPlatformError, IOError)
  66. else:
  67. build_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  68. class custom_build_ext(build_ext):
  69. """Allow C extension building to fail.
  70. The C extension speeds up BSON encoding, but is not essential.
  71. """
  72. warning_message = """
  73. **************************************************************
  74. WARNING: %s could not
  75. be compiled. No C extensions are essential for PyMongo to run,
  76. although they do result in significant speed improvements.
  77. If you are seeing this message on Linux you probably need to
  78. install GCC and/or the Python development package for your
  79. version of Python. Python development package names for popular
  80. Linux distributions include:
  81. RHEL/CentOS: python-devel
  82. Debian/Ubuntu: python-dev
  83. %s
  84. **************************************************************
  85. """
  86. def run(self):
  87. try:
  88. build_ext.run(self)
  89. except DistutilsPlatformError, e:
  90. print e
  91. print self.warning_message % ("Extension modules",
  92. "There was an issue with your "
  93. "platform configuration "
  94. "- see above.")
  95. def build_extension(self, ext):
  96. if sys.version_info[:3] >= (2, 4, 0):
  97. try:
  98. build_ext.build_extension(self, ext)
  99. except build_errors, e:
  100. print e
  101. print self.warning_message % ("The %s extension "
  102. "module" % ext.name,
  103. "Above is the ouput showing how "
  104. "the compilation failed.")
  105. else:
  106. print self.warning_message % ("The %s extension module" % ext.name,
  107. "Please use Python >= 2.4 to take "
  108. "advantage of the extension.")
  109. c_ext = Feature(
  110. "optional C extensions",
  111. standard=True,
  112. ext_modules=[Extension('bson._cbson',
  113. include_dirs=['bson'],
  114. sources=['bson/_cbsonmodule.c',
  115. 'bson/time64.c',
  116. 'bson/buffer.c',
  117. 'bson/encoding_helpers.c']),
  118. Extension('pymongo._cmessage',
  119. include_dirs=['bson'],
  120. sources=['pymongo/_cmessagemodule.c',
  121. 'bson/_cbsonmodule.c',
  122. 'bson/time64.c',
  123. 'bson/buffer.c',
  124. 'bson/encoding_helpers.c'])])
  125. if "--no_ext" in sys.argv:
  126. sys.argv = [x for x in sys.argv if x != "--no_ext"]
  127. features = {}
  128. elif (sys.platform.startswith("java") or
  129. sys.platform == "cli" or
  130. "PyPy" in sys.version):
  131. print """
  132. *****************************************************
  133. The optional C extensions are currently not supported
  134. by this python implementation.
  135. *****************************************************
  136. """
  137. features = {}
  138. elif sys.byteorder == "big":
  139. print """
  140. *****************************************************
  141. The optional C extensions are currently not supported
  142. on big endian platforms and will not be built.
  143. Performance may be degraded.
  144. *****************************************************
  145. """
  146. features = {}
  147. else:
  148. features = {"c-ext": c_ext}
  149. setup(
  150. name="pymongo",
  151. version=version,
  152. description="Python driver for MongoDB <http://www.mongodb.org>",
  153. long_description=readme_content,
  154. author="Mike Dirolf",
  155. author_email="mongodb-user@googlegroups.com",
  156. maintainer="Bernie Hackett",
  157. maintainer_email="bernie@10gen.com",
  158. url="http://github.com/mongodb/mongo-python-driver",
  159. keywords=["mongo", "mongodb", "pymongo", "gridfs", "bson"],
  160. packages=["bson", "pymongo", "gridfs"],
  161. install_requires=[],
  162. features=features,
  163. license="Apache License, Version 2.0",
  164. tests_require=['nose'],
  165. test_suite="nose.collector",
  166. classifiers=[
  167. "Development Status :: 5 - Production/Stable",
  168. "Intended Audience :: Developers",
  169. "License :: OSI Approved :: Apache Software License",
  170. "Operating System :: MacOS :: MacOS X",
  171. "Operating System :: Microsoft :: Windows",
  172. "Operating System :: POSIX",
  173. "Programming Language :: Python",
  174. "Topic :: Database"],
  175. cmdclass={"build_ext": custom_build_ext,
  176. "doc": doc})