setup.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. try:
  4. from setuptools import setup, find_packages
  5. from setuptools.command.test import test
  6. except ImportError:
  7. raise
  8. from ez_setup import use_setuptools
  9. use_setuptools()
  10. from setuptools import setup, find_packages # noqa
  11. from setuptools.command.test import test # noqa
  12. import os
  13. import sys
  14. import codecs
  15. CELERY_COMPAT_PROGRAMS = int(os.environ.get('CELERY_COMPAT_PROGRAMS', 1))
  16. if sys.version_info < (2, 6):
  17. raise Exception('Celery 3.1 requires Python 2.6 or higher.')
  18. downgrade_packages = [
  19. 'celery.app.task',
  20. 'celery.concurrency.processes',
  21. ]
  22. orig_path = sys.path[:]
  23. for path in (os.path.curdir, os.getcwd()):
  24. if path in sys.path:
  25. sys.path.remove(path)
  26. try:
  27. import imp
  28. import shutil
  29. for pkg in downgrade_packages:
  30. try:
  31. parent, module = pkg.rsplit('.', 1)
  32. print('- Trying to upgrade %r in %r' % (module, parent))
  33. parent_mod = __import__(parent, None, None, [parent])
  34. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  35. if mod_path.endswith('/' + module):
  36. print('- force upgrading previous installation')
  37. print(' - removing {0!r} package...'.format(mod_path))
  38. try:
  39. shutil.rmtree(os.path.abspath(mod_path))
  40. except Exception:
  41. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  42. mod_path, sys.exc_info[1]))
  43. except ImportError:
  44. print('- upgrade %s: no old version found.' % module)
  45. except:
  46. pass
  47. finally:
  48. sys.path[:] = orig_path
  49. NAME = 'celery'
  50. entrypoints = {}
  51. extra = {}
  52. # -*- Classifiers -*-
  53. classes = """
  54. Development Status :: 5 - Production/Stable
  55. License :: OSI Approved :: BSD License
  56. Topic :: System :: Distributed Computing
  57. Topic :: Software Development :: Object Brokering
  58. Programming Language :: Python
  59. Programming Language :: Python :: 2
  60. Programming Language :: Python :: 2.6
  61. Programming Language :: Python :: 2.7
  62. Programming Language :: Python :: 3
  63. Programming Language :: Python :: 3.2
  64. Programming Language :: Python :: 3.3
  65. Programming Language :: Python :: Implementation :: CPython
  66. Programming Language :: Python :: Implementation :: PyPy
  67. Programming Language :: Python :: Implementation :: Jython
  68. Operating System :: OS Independent
  69. Operating System :: POSIX
  70. Operating System :: Microsoft :: Windows
  71. Operating System :: MacOS :: MacOS X
  72. """
  73. classifiers = [s.strip() for s in classes.split('\n') if s]
  74. # -*- Python 3 -*-
  75. is_py3k = sys.version_info[0] == 3
  76. if is_py3k:
  77. extra.update(use_2to3=True)
  78. # -*- Distribution Meta -*-
  79. import re
  80. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  81. re_vers = re.compile(r'VERSION\s*=\s*\((.*?)\)')
  82. re_doc = re.compile(r'^"""(.+?)"""')
  83. rq = lambda s: s.strip("\"'")
  84. def add_default(m):
  85. attr_name, attr_value = m.groups()
  86. return ((attr_name, rq(attr_value)), )
  87. def add_version(m):
  88. v = list(map(rq, m.groups()[0].split(', ')))
  89. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])), )
  90. def add_doc(m):
  91. return (('doc', m.groups()[0]), )
  92. pats = {re_meta: add_default,
  93. re_vers: add_version,
  94. re_doc: add_doc}
  95. here = os.path.abspath(os.path.dirname(__file__))
  96. meta_fh = open(os.path.join(here, 'celery/__init__.py'))
  97. try:
  98. meta = {}
  99. for line in meta_fh:
  100. if line.strip() == '# -eof meta-':
  101. break
  102. for pattern, handler in pats.items():
  103. m = pattern.match(line.strip())
  104. if m:
  105. meta.update(handler(m))
  106. finally:
  107. meta_fh.close()
  108. # -*- Custom Commands -*-
  109. class quicktest(test):
  110. extra_env = dict(SKIP_RLIMITS=1, QUICKTEST=1)
  111. def run(self, *args, **kwargs):
  112. for env_name, env_value in self.extra_env.items():
  113. os.environ[env_name] = str(env_value)
  114. test.run(self, *args, **kwargs)
  115. # -*- Installation Requires -*-
  116. py_version = sys.version_info
  117. is_jython = sys.platform.startswith('java')
  118. is_pypy = hasattr(sys, 'pypy_version_info')
  119. def strip_comments(l):
  120. return l.split('#', 1)[0].strip()
  121. def reqs(f):
  122. return filter(None, [strip_comments(l) for l in open(
  123. os.path.join(os.getcwd(), 'requirements', f)).readlines()])
  124. install_requires = reqs('default-py3k.txt' if is_py3k else 'default.txt')
  125. if is_jython:
  126. install_requires.extend(reqs('jython.txt'))
  127. # -*- Tests Requires -*-
  128. tests_require = reqs('test.txt')
  129. # -*- Long Description -*-
  130. if os.path.exists('README.rst'):
  131. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  132. else:
  133. long_description = 'See http://pypi.python.org/pypi/celery'
  134. # -*- Entry Points -*- #
  135. console_scripts = entrypoints['console_scripts'] = [
  136. 'celery = celery.__main__:main',
  137. ]
  138. if CELERY_COMPAT_PROGRAMS:
  139. console_scripts.extend([
  140. 'celeryd = celery.__main__:_compat_worker',
  141. 'celerybeat = celery.bin.celerybeat:main',
  142. 'camqadm = celery.bin.camqadm:main',
  143. 'celeryev = celery.bin.celeryev:main',
  144. 'celeryctl = celery.bin.celeryctl:main',
  145. 'celeryd-multi = celery.bin.celeryd_multi:main',
  146. ])
  147. # bundles: Only relevant for Celery developers.
  148. entrypoints['bundle.bundles'] = ['celery = celery.contrib.bundles:bundles']
  149. # -*- %%% -*-
  150. setup(
  151. name=NAME,
  152. version=meta['VERSION'],
  153. description=meta['doc'],
  154. author=meta['author'],
  155. author_email=meta['contact'],
  156. url=meta['homepage'],
  157. platforms=['any'],
  158. license='BSD',
  159. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  160. zip_safe=False,
  161. install_requires=install_requires,
  162. tests_require=tests_require,
  163. test_suite='nose.collector',
  164. cmdclass={'quicktest': quicktest},
  165. classifiers=classifiers,
  166. entry_points=entrypoints,
  167. long_description=long_description,
  168. **extra)