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"]
  9. if sys.version_info >= (3, 0):
  10. extra.update(use_2to3=True)
  11. elif sys.version_info <= (2, 6):
  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. import celery as distmeta
  28. def with_dist_not_in_path(fun):
  29. def _inner(*args, **kwargs):
  30. cwd = os.getcwd()
  31. removed = []
  32. for path in (cwd, cwd + "/", "."):
  33. try:
  34. i = sys.path.index(path)
  35. except ValueError:
  36. pass
  37. else:
  38. removed.append((i, path))
  39. sys.path.remove(path)
  40. try:
  41. dist_module = sys.modules.pop("celery", None)
  42. try:
  43. import celery as existing_module
  44. except ImportError:
  45. pass
  46. else:
  47. kwargs["celery"] = existing_module
  48. return fun(*args, **kwargs)
  49. finally:
  50. for i, path in removed:
  51. sys.path.insert(i, path)
  52. if dist_module:
  53. sys.modules["celery"] = dist_module
  54. return _inner
  55. class Upgrade(object):
  56. old_modules = ("platform", )
  57. def run(self, dist=False):
  58. detect_ = self.detect_existing_installation
  59. if not dist:
  60. detect = with_dist_not_in_path(detect_)
  61. else:
  62. detect = lambda: detect_(distmeta)
  63. path = detect()
  64. if path:
  65. self.remove_modules(path)
  66. def detect_existing_installation(self, celery=None):
  67. path = os.path.dirname(celery.__file__)
  68. sys.stderr.write("* Upgrading old Celery from: \n\t%r\n" % path)
  69. return path
  70. def try_remove(self, file):
  71. try:
  72. os.remove(file)
  73. except OSError:
  74. pass
  75. def remove_modules(self, path):
  76. for module_name in self.old_modules:
  77. sys.stderr.write("* Removing old %s.py...\n" % module_name)
  78. self.try_remove(os.path.join(path, "%s.py" % module_name))
  79. self.try_remove(os.path.join(path, "%s.pyc" % module_name))
  80. class mytest(test):
  81. def run(self, *args, **kwargs):
  82. Upgrade().run(dist=True)
  83. test.run(self, *args, **kwargs)
  84. class quicktest(mytest):
  85. extra_env = dict(SKIP_RLIMITS=1, QUICKTEST=1)
  86. def run(self, *args, **kwargs):
  87. for env_name, env_value in self.extra_env.items():
  88. os.environ[env_name] = str(env_value)
  89. mytest.run(self, *args, **kwargs)
  90. class upgrade(Command):
  91. user_options = []
  92. def run(self, *args, **kwargs):
  93. Upgrade().run()
  94. def initialize_options(self):
  95. pass
  96. def finalize_options(self):
  97. pass
  98. class upgrade_and_install(install):
  99. def run(self, *args, **kwargs):
  100. Upgrade().run()
  101. install.run(self, *args, **kwargs)
  102. install_requires = []
  103. try:
  104. import importlib
  105. except ImportError:
  106. install_requires.append("importlib")
  107. install_requires.extend([
  108. "python-dateutil",
  109. "anyjson",
  110. "kombu>=0.9.1",
  111. "pyparsing",
  112. ])
  113. py_version = sys.version_info
  114. if sys.version_info < (2, 6) and not sys.platform.startswith("java"):
  115. install_requires.append("multiprocessing")
  116. if sys.version_info < (2, 5):
  117. install_requires.append("uuid")
  118. if os.path.exists("README.rst"):
  119. long_description = codecs.open("README.rst", "r", "utf-8").read()
  120. else:
  121. long_description = "See http://pypi.python.org/pypi/celery"
  122. console_scripts = [
  123. 'celerybeat = celery.bin.celerybeat:main',
  124. 'camqadm = celery.bin.camqadm:main',
  125. 'celeryev = celery.bin.celeryev:main',
  126. 'celeryctl = celery.bin.celeryctl:main',
  127. 'celeryd-multi = celery.bin.celeryd_multi:main',
  128. ]
  129. import platform
  130. if platform.system() == "Windows":
  131. console_scripts.append('celeryd = celery.bin.celeryd:windows_main')
  132. else:
  133. console_scripts.append('celeryd = celery.bin.celeryd:main')
  134. setup(
  135. name="celery",
  136. version=distmeta.__version__,
  137. description=distmeta.__doc__,
  138. author=distmeta.__author__,
  139. author_email=distmeta.__contact__,
  140. url=distmeta.__homepage__,
  141. platforms=["any"],
  142. license="BSD",
  143. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  144. scripts=["bin/celeryd", "bin/celerybeat",
  145. "bin/camqadm", "bin/celeryd-multi",
  146. "bin/celeryev"],
  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. )