setup.py 5.6 KB

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