PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/SQLAlchemy-0.7.8/setup.py

#
Python | 196 lines | 167 code | 19 blank | 10 comment | 26 complexity | 0773a63255749f4f9884e47cada895da MD5 | raw file
  1. """setup.py
  2. Please see README for basic installation instructions.
  3. """
  4. import os
  5. import re
  6. import sys
  7. from distutils.command.build_ext import build_ext
  8. from distutils.errors import (CCompilerError, DistutilsExecError,
  9. DistutilsPlatformError)
  10. try:
  11. from setuptools import setup, Extension, Feature
  12. has_setuptools = True
  13. except ImportError:
  14. has_setuptools = False
  15. from distutils.core import setup, Extension
  16. Feature = None
  17. try: # Python 3
  18. from distutils.command.build_py import build_py_2to3 as build_py
  19. except ImportError: # Python 2
  20. from distutils.command.build_py import build_py
  21. cmdclass = {}
  22. pypy = hasattr(sys, 'pypy_version_info')
  23. jython = sys.platform.startswith('java')
  24. py3k = False
  25. extra = {}
  26. if sys.version_info < (2, 4):
  27. raise Exception("SQLAlchemy requires Python 2.4 or higher.")
  28. elif sys.version_info >= (3, 0):
  29. py3k = True
  30. if has_setuptools:
  31. extra.update(
  32. use_2to3=True,
  33. )
  34. else:
  35. cmdclass['build_py'] = build_py
  36. ext_modules = [
  37. Extension('sqlalchemy.cprocessors',
  38. sources=['lib/sqlalchemy/cextension/processors.c']),
  39. Extension('sqlalchemy.cresultproxy',
  40. sources=['lib/sqlalchemy/cextension/resultproxy.c'])
  41. ]
  42. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  43. if sys.platform == 'win32' and sys.version_info > (2, 6):
  44. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  45. # find the compiler
  46. ext_errors += (IOError,)
  47. class BuildFailed(Exception):
  48. def __init__(self):
  49. self.cause = sys.exc_info()[1] # work around py 2/3 different syntax
  50. class ve_build_ext(build_ext):
  51. # This class allows C extension building to fail.
  52. def run(self):
  53. try:
  54. build_ext.run(self)
  55. except DistutilsPlatformError:
  56. raise BuildFailed()
  57. def build_extension(self, ext):
  58. try:
  59. build_ext.build_extension(self, ext)
  60. except ext_errors:
  61. raise BuildFailed()
  62. except ValueError:
  63. # this can happen on Windows 64 bit, see Python issue 7511
  64. if "'path'" in str(sys.exc_info()[1]): # works with both py 2/3
  65. raise BuildFailed()
  66. raise
  67. cmdclass['build_ext'] = ve_build_ext
  68. def status_msgs(*msgs):
  69. print('*' * 75)
  70. for msg in msgs:
  71. print(msg)
  72. print('*' * 75)
  73. def find_packages(dir_):
  74. packages = []
  75. for pkg in ['sqlalchemy']:
  76. for _dir, subdirectories, files in (
  77. os.walk(os.path.join(dir_, pkg))
  78. ):
  79. if '__init__.py' in files:
  80. lib, fragment = _dir.split(os.sep, 1)
  81. packages.append(fragment.replace(os.sep, '.'))
  82. return packages
  83. v_file = open(os.path.join(os.path.dirname(__file__),
  84. 'lib', 'sqlalchemy', '__init__.py'))
  85. VERSION = re.compile(r".*__version__ = '(.*?)'",
  86. re.S).match(v_file.read()).group(1)
  87. v_file.close()
  88. r_file = open(os.path.join(os.path.dirname(__file__), 'README.rst'))
  89. readme = r_file.read()
  90. r_file.close()
  91. def run_setup(with_cext):
  92. kwargs = extra.copy()
  93. if with_cext:
  94. if Feature:
  95. kwargs['features'] = {'cextensions': Feature(
  96. "optional C speed-enhancements",
  97. standard=True,
  98. ext_modules=ext_modules
  99. )}
  100. else:
  101. kwargs['ext_modules'] = ext_modules
  102. setup(name="SQLAlchemy",
  103. version=VERSION,
  104. description="Database Abstraction Library",
  105. author="Mike Bayer",
  106. author_email="mike_mp@zzzcomputing.com",
  107. url="http://www.sqlalchemy.org",
  108. packages=find_packages('lib'),
  109. package_dir={'': 'lib'},
  110. license="MIT License",
  111. cmdclass=cmdclass,
  112. tests_require=['nose >= 0.11'],
  113. test_suite="sqla_nose",
  114. long_description=readme,
  115. classifiers=[
  116. "Development Status :: 5 - Production/Stable",
  117. "Intended Audience :: Developers",
  118. "License :: OSI Approved :: MIT License",
  119. "Programming Language :: Python",
  120. "Programming Language :: Python :: 3",
  121. "Programming Language :: Python :: Implementation :: CPython",
  122. "Programming Language :: Python :: Implementation :: Jython",
  123. "Programming Language :: Python :: Implementation :: PyPy",
  124. "Topic :: Database :: Front-Ends",
  125. "Operating System :: OS Independent",
  126. ],
  127. **kwargs
  128. )
  129. def monkeypatch2to3():
  130. from sa2to3 import refactor_string
  131. from lib2to3.refactor import RefactoringTool
  132. RefactoringTool.old_refactor_string = RefactoringTool.refactor_string
  133. RefactoringTool.refactor_string = refactor_string
  134. def unmonkeypatch2to3():
  135. from lib2to3.refactor import RefactoringTool
  136. if hasattr(RefactoringTool, 'old_refactor_string'):
  137. RefactoringTool.refactor_string = RefactoringTool.old_refactor_string
  138. if pypy or jython or py3k:
  139. if py3k:
  140. # monkeypatch our preprocessor onto the 2to3 tool.
  141. monkeypatch2to3()
  142. try:
  143. run_setup(False)
  144. finally:
  145. if py3k:
  146. # unmonkeypatch to not stomp other setup.py's that are compiled
  147. # and exec'd and which also require 2to3 fixing
  148. unmonkeypatch2to3()
  149. status_msgs(
  150. "WARNING: C extensions are not supported on " +
  151. "this Python platform, speedups are not enabled.",
  152. "Plain-Python build succeeded."
  153. )
  154. else:
  155. try:
  156. run_setup(True)
  157. except BuildFailed:
  158. exc = sys.exc_info()[1] # work around py 2/3 different syntax
  159. status_msgs(
  160. exc.cause,
  161. "WARNING: The C extension could not be compiled, " +
  162. "speedups are not enabled.",
  163. "Failure information, if any, is above.",
  164. "Retrying the build without the C extension now."
  165. )
  166. run_setup(False)
  167. status_msgs(
  168. "WARNING: The C extension could not be compiled, " +
  169. "speedups are not enabled.",
  170. "Plain-Python build succeeded."
  171. )