setup.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import sys
  5. import codecs
  6. import platform
  7. extra = {}
  8. tests_require = ["nose", "nose-cover3", "sqlalchemy"]
  9. if sys.version_info >= (3, 0):
  10. extra.update(use_2to3=True)
  11. elif sys.version_info < (2, 7):
  12. tests_require.append("unittest2")
  13. elif sys.version_info <= (2, 5):
  14. tests_require.append("simplejson")
  15. if sys.version_info < (2, 4):
  16. raise Exception("Celery requires Python 2.4 or higher.")
  17. try:
  18. from setuptools import setup, find_packages, Command
  19. from setuptools.command.test import test
  20. from setuptools.command.install import install
  21. except ImportError:
  22. from ez_setup import use_setuptools
  23. use_setuptools()
  24. from setuptools import setup, find_packages, Command
  25. from setuptools.command.test import test
  26. from setuptools.command.install import install
  27. os.environ["CELERY_NO_EVAL"] = "yes"
  28. import celery as distmeta
  29. os.environ.pop("CELERY_NO_EVAL", None)
  30. sys.modules.pop("celery", None)
  31. def with_dist_not_in_path(fun):
  32. def _inner(*args, **kwargs):
  33. cwd = os.getcwd()
  34. removed = []
  35. for path in (cwd, cwd + "/", "."):
  36. try:
  37. i = sys.path.index(path)
  38. except ValueError:
  39. pass
  40. else:
  41. removed.append((i, path))
  42. sys.path.remove(path)
  43. try:
  44. dist_module = sys.modules.pop("celery", None)
  45. try:
  46. import celery as existing_module
  47. except ImportError:
  48. pass
  49. else:
  50. kwargs["celery"] = existing_module
  51. return fun(*args, **kwargs)
  52. finally:
  53. for i, path in removed:
  54. sys.path.insert(i, path)
  55. if dist_module:
  56. sys.modules["celery"] = dist_module
  57. return _inner
  58. class Upgrade(object):
  59. old_modules = ("platform", )
  60. def run(self, dist=False):
  61. detect_ = self.detect_existing_installation
  62. if not dist:
  63. detect = with_dist_not_in_path(detect_)
  64. else:
  65. detect = lambda: detect_(distmeta)
  66. path = detect()
  67. if path:
  68. self.remove_modules(path)
  69. def detect_existing_installation(self, celery=None):
  70. path = os.path.dirname(celery.__file__)
  71. sys.stderr.write("* Upgrading old Celery from: \n\t%r\n" % path)
  72. return path
  73. def try_remove(self, file):
  74. try:
  75. os.remove(file)
  76. except OSError:
  77. pass
  78. def remove_modules(self, path):
  79. for module_name in self.old_modules:
  80. sys.stderr.write("* Removing old %s.py...\n" % module_name)
  81. self.try_remove(os.path.join(path, "%s.py" % module_name))
  82. self.try_remove(os.path.join(path, "%s.pyc" % module_name))
  83. class mytest(test):
  84. def run(self, *args, **kwargs):
  85. Upgrade().run(dist=True)
  86. test.run(self, *args, **kwargs)
  87. class quicktest(mytest):
  88. extra_env = dict(SKIP_RLIMITS=1, QUICKTEST=1)
  89. def run(self, *args, **kwargs):
  90. for env_name, env_value in self.extra_env.items():
  91. os.environ[env_name] = str(env_value)
  92. mytest.run(self, *args, **kwargs)
  93. class upgrade(Command):
  94. user_options = []
  95. def run(self, *args, **kwargs):
  96. Upgrade().run()
  97. def initialize_options(self):
  98. pass
  99. def finalize_options(self):
  100. pass
  101. class upgrade_and_install(install):
  102. def run(self, *args, **kwargs):
  103. Upgrade().run()
  104. install.run(self, *args, **kwargs)
  105. install_requires = []
  106. try:
  107. import importlib
  108. except ImportError:
  109. install_requires.append("importlib")
  110. install_requires.extend([
  111. "python-dateutil",
  112. "anyjson",
  113. "kombu>=1.0.0b4",
  114. "pyparsing>=1.5.0",
  115. ])
  116. py_version = sys.version_info
  117. if sys.version_info < (2, 6) and not sys.platform.startswith("java"):
  118. install_requires.append("multiprocessing")
  119. if sys.version_info < (2, 5):
  120. install_requires.append("uuid")
  121. if os.path.exists("README.rst"):
  122. long_description = codecs.open("README.rst", "r", "utf-8").read()
  123. else:
  124. long_description = "See http://pypi.python.org/pypi/celery"
  125. console_scripts = [
  126. 'celerybeat = celery.bin.celerybeat:main',
  127. 'camqadm = celery.bin.camqadm:main',
  128. 'celeryev = celery.bin.celeryev:main',
  129. 'celeryctl = celery.bin.celeryctl:main',
  130. 'celeryd-multi = celery.bin.celeryd_multi:main',
  131. ]
  132. import platform
  133. if platform.system() == "Windows":
  134. console_scripts.append('celeryd = celery.bin.celeryd:windows_main')
  135. else:
  136. console_scripts.append('celeryd = celery.bin.celeryd:main')
  137. setup(
  138. name="celery",
  139. version=distmeta.__version__,
  140. description=distmeta.__doc__,
  141. author=distmeta.__author__,
  142. author_email=distmeta.__contact__,
  143. url=distmeta.__homepage__,
  144. platforms=["any"],
  145. license="BSD",
  146. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  147. zip_safe=False,
  148. install_requires=install_requires,
  149. tests_require=tests_require,
  150. cmdclass={"install": upgrade_and_install,
  151. "upgrade": upgrade,
  152. "test": mytest,
  153. "quicktest": quicktest},
  154. test_suite="nose.collector",
  155. classifiers=[
  156. "Development Status :: 5 - Production/Stable",
  157. "Operating System :: OS Independent",
  158. "Environment :: No Input/Output (Daemon)",
  159. "Intended Audience :: Developers",
  160. "License :: OSI Approved :: BSD License",
  161. "Operating System :: POSIX",
  162. "Topic :: Communications",
  163. "Topic :: System :: Distributed Computing",
  164. "Topic :: Software Development :: Libraries :: Python Modules",
  165. "Programming Language :: Python",
  166. "Programming Language :: Python :: 2",
  167. "Programming Language :: Python :: 2.4",
  168. "Programming Language :: Python :: 2.5",
  169. "Programming Language :: Python :: 2.6",
  170. "Programming Language :: Python :: 2.7",
  171. ],
  172. entry_points={
  173. 'console_scripts': console_scripts,
  174. },
  175. long_description=long_description,
  176. **extra
  177. )