setup.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from setuptools import setup, find_packages
  4. import os
  5. import sys
  6. import codecs
  7. CELERY_COMPAT_PROGRAMS = int(os.environ.get('CELERY_COMPAT_PROGRAMS', 1))
  8. if sys.version_info < (2, 7):
  9. raise Exception('Celery 3.2 requires Python 2.7 or higher.')
  10. # -*- Upgrading from older versions -*-
  11. downgrade_packages = [
  12. 'celery.app.task',
  13. ]
  14. orig_path = sys.path[:]
  15. for path in (os.path.curdir, os.getcwd()):
  16. if path in sys.path:
  17. sys.path.remove(path)
  18. try:
  19. import imp
  20. import shutil
  21. for pkg in downgrade_packages:
  22. try:
  23. parent, module = pkg.rsplit('.', 1)
  24. print('- Trying to upgrade %r in %r' % (module, parent))
  25. parent_mod = __import__(parent, None, None, [parent])
  26. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  27. if mod_path.endswith('/' + module):
  28. print('- force upgrading previous installation')
  29. print(' - removing {0!r} package...'.format(mod_path))
  30. try:
  31. shutil.rmtree(os.path.abspath(mod_path))
  32. except Exception:
  33. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  34. mod_path, sys.exc_info[1]))
  35. except ImportError:
  36. print('- upgrade %s: no old version found.' % module)
  37. except:
  38. pass
  39. finally:
  40. sys.path[:] = orig_path
  41. PY3 = sys.version_info[0] == 3
  42. JYTHON = sys.platform.startswith('java')
  43. PYPY = hasattr(sys, 'pypy_version_info')
  44. NAME = 'celery'
  45. entrypoints = {}
  46. extra = {}
  47. # -*- Classifiers -*-
  48. classes = """
  49. Development Status :: 5 - Production/Stable
  50. License :: OSI Approved :: BSD License
  51. Topic :: System :: Distributed Computing
  52. Topic :: Software Development :: Object Brokering
  53. Programming Language :: Python
  54. Programming Language :: Python :: 2
  55. Programming Language :: Python :: 2.7
  56. Programming Language :: Python :: 3
  57. Programming Language :: Python :: 3.3
  58. Programming Language :: Python :: 3.4
  59. Programming Language :: Python :: Implementation :: CPython
  60. Programming Language :: Python :: Implementation :: PyPy
  61. Programming Language :: Python :: Implementation :: Jython
  62. Operating System :: OS Independent
  63. """
  64. classifiers = [s.strip() for s in classes.split('\n') if s]
  65. # -*- Distribution Meta -*-
  66. import re
  67. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  68. re_vers = re.compile(r'VERSION\s*=.*?\((.*?)\)')
  69. re_doc = re.compile(r'^"""(.+?)"""')
  70. rq = lambda s: s.strip("\"'")
  71. def add_default(m):
  72. attr_name, attr_value = m.groups()
  73. return ((attr_name, rq(attr_value)), )
  74. def add_version(m):
  75. v = list(map(rq, m.groups()[0].split(', ')))
  76. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])), )
  77. def add_doc(m):
  78. return (('doc', m.groups()[0]), )
  79. pats = {re_meta: add_default,
  80. re_vers: add_version,
  81. re_doc: add_doc}
  82. here = os.path.abspath(os.path.dirname(__file__))
  83. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  84. meta = {}
  85. for line in meta_fh:
  86. if line.strip() == '# -eof meta-':
  87. break
  88. for pattern, handler in pats.items():
  89. m = pattern.match(line.strip())
  90. if m:
  91. meta.update(handler(m))
  92. # -*- Installation Requires -*-
  93. def strip_comments(l):
  94. return l.split('#', 1)[0].strip()
  95. def reqs(*f):
  96. return [
  97. r for r in (
  98. strip_comments(l) for l in open(
  99. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  100. ) if r]
  101. install_requires = reqs('default.txt')
  102. if JYTHON:
  103. install_requires.extend(reqs('jython.txt'))
  104. # -*- Tests Requires -*-
  105. tests_require = reqs('test3.txt' if PY3 else 'test.txt')
  106. # -*- Long Description -*-
  107. if os.path.exists('README.rst'):
  108. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  109. else:
  110. long_description = 'See http://pypi.python.org/pypi/celery'
  111. # -*- Entry Points -*- #
  112. console_scripts = entrypoints['console_scripts'] = [
  113. 'celery = celery.__main__:main',
  114. ]
  115. if CELERY_COMPAT_PROGRAMS:
  116. console_scripts.extend([
  117. 'celeryd = celery.__main__:_compat_worker',
  118. 'celerybeat = celery.__main__:_compat_beat',
  119. 'celeryd-multi = celery.__main__:_compat_multi',
  120. ])
  121. # -*- Extras -*-
  122. extras = lambda *p: reqs('extras', *p)
  123. # Celery specific
  124. features = {
  125. 'auth', 'cassandra', 'memcache', 'couchbase', 'threads',
  126. 'eventlet', 'gevent', 'msgpack', 'yaml', 'redis',
  127. 'mongodb', 'sqs', 'couchdb', 'riak', 'beanstalk', 'zookeeper',
  128. 'zeromq', 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq',
  129. }
  130. extras_require = {x: extras(x + '.txt') for x in features}
  131. extra['extras_require'] = extras_require
  132. # -*- %%% -*-
  133. setup(
  134. name=NAME,
  135. version=meta['VERSION'],
  136. description=meta['doc'],
  137. author=meta['author'],
  138. author_email=meta['contact'],
  139. url=meta['homepage'],
  140. platforms=['any'],
  141. license='BSD',
  142. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  143. include_package_data=False,
  144. zip_safe=False,
  145. install_requires=install_requires,
  146. tests_require=tests_require,
  147. test_suite='nose.collector',
  148. classifiers=classifiers,
  149. entry_points=entrypoints,
  150. long_description=long_description,
  151. **extra)