setup.py 5.9 KB

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