PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/setup.py

https://github.com/fajran/mongo-python-driver
Python | 152 lines | 146 code | 5 blank | 1 comment | 7 complexity | 8d326a3bb2dfa764b4c1635b7899e561 MD5 | raw file
Possible License(s): Apache-2.0
  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. requirements = []
  21. try:
  22. import xml.etree.ElementTree
  23. except ImportError:
  24. requirements.append("elementtree")
  25. f = open("README.rst")
  26. try:
  27. try:
  28. readme_content = f.read()
  29. except:
  30. readme_content = ""
  31. finally:
  32. f.close()
  33. class GenerateDoc(Command):
  34. user_options = []
  35. def initialize_options(self):
  36. pass
  37. def finalize_options(self):
  38. pass
  39. def run(self):
  40. path = "doc/_build/%s" % version
  41. # shutil.rmtree("doc/_build", ignore_errors=True)
  42. try:
  43. os.makedirs(path)
  44. except:
  45. pass
  46. if has_subprocess:
  47. subprocess.call(["sphinx-build", "-b", "html", "doc", path])
  48. print ""
  49. print "Documentation generated:"
  50. print " %s/index.html" % path
  51. else:
  52. print """
  53. `setup.py doc` is not supported for this version of Python.
  54. Please ask in the user forums for help.
  55. """
  56. if sys.platform == 'win32' and sys.version_info > (2, 6):
  57. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  58. # find the compiler
  59. build_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
  60. IOError)
  61. else:
  62. build_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  63. class custom_build_ext(build_ext):
  64. """Allow C extension building to fail.
  65. The C extension speeds up BSON encoding, but is not essential.
  66. """
  67. warning_message = """
  68. **************************************************************
  69. WARNING: %s could not
  70. be compiled. No C extensions are essential for PyMongo to run,
  71. although they do result in significant speed improvements.
  72. %s
  73. **************************************************************
  74. """
  75. def run(self):
  76. try:
  77. build_ext.run(self)
  78. except DistutilsPlatformError, e:
  79. print e
  80. print self.warning_message % ("Extension modules",
  81. "There was an issue with your "
  82. "platform configuration - see above.")
  83. def build_extension(self, ext):
  84. if sys.version_info[:3] >= (2, 4, 0):
  85. try:
  86. build_ext.build_extension(self, ext)
  87. except build_errors:
  88. print self.warning_message % ("The %s extension module" % ext.name,
  89. "Above is the ouput showing how "
  90. "the compilation failed.")
  91. else:
  92. print self.warning_message % ("The %s extension module" % ext.name,
  93. "Please use Python >= 2.4 to take "
  94. "advantage of the extension.")
  95. c_ext = Feature(
  96. "optional C extension",
  97. standard=True,
  98. ext_modules=[Extension('pymongo._cbson', ['pymongo/_cbsonmodule.c'])])
  99. if "--no_ext" in sys.argv:
  100. sys.argv = [x for x in sys.argv if x != "--no_ext"]
  101. features = {}
  102. else:
  103. features = {"c-ext": c_ext}
  104. setup(
  105. name="pymongo",
  106. version=version,
  107. description="Python driver for MongoDB <http://www.mongodb.org>",
  108. long_description=readme_content,
  109. author="Mike Dirolf",
  110. author_email="mongodb-user@googlegroups.com",
  111. url="http://github.com/mongodb/mongo-python-driver",
  112. keywords=["mongo", "mongodb", "pymongo", "gridfs"],
  113. packages=["pymongo", "gridfs"],
  114. install_requires=requirements,
  115. features=features,
  116. license="Apache License, Version 2.0",
  117. test_suite="nose.collector",
  118. classifiers=[
  119. "Development Status :: 5 - Production/Stable",
  120. "Intended Audience :: Developers",
  121. "License :: OSI Approved :: Apache Software License",
  122. "Operating System :: MacOS :: MacOS X",
  123. "Operating System :: Microsoft :: Windows",
  124. "Operating System :: POSIX",
  125. "Programming Language :: Python",
  126. "Topic :: Database"],
  127. cmdclass={"build_ext": custom_build_ext,
  128. "doc": GenerateDoc})