| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- # -*- coding: utf-8 -*-
- """Distributed Task Queue"""
- # :copyright: (c) 2009 - 2012 Ask Solem and individual contributors,
- # All rights reserved.
- # :copyright: (c) 2012-2013 GoPivotal, Inc., All rights reserved.
- # :license: BSD (3 Clause), see LICENSE for more details.
- from __future__ import absolute_import
- SERIES = 'Cipater'
- VERSION = (3, 1, 0, 'rc4')
- __version__ = '.'.join(str(p) for p in VERSION[0:3]) + ''.join(VERSION[3:])
- __author__ = 'Ask Solem'
- __contact__ = 'ask@celeryproject.org'
- __homepage__ = 'http://celeryproject.org'
- __docformat__ = 'restructuredtext'
- __all__ = [
- 'Celery', 'bugreport', 'shared_task', 'task',
- 'current_app', 'current_task',
- 'chain', 'chord', 'chunks', 'group', 'subtask',
- 'xmap', 'xstarmap', 'uuid', 'version', '__version__',
- ]
- VERSION_BANNER = '{0} ({1})'.format(__version__, SERIES)
- # -eof meta-
- import os
- import sys
- if os.environ.get('C_IMPDEBUG'): # pragma: no cover
- from .five import builtins
- real_import = builtins.__import__
- def debug_import(name, locals=None, globals=None,
- fromlist=None, level=-1):
- glob = globals or getattr(sys, 'emarfteg_'[::-1])(1).f_globals
- importer_name = glob and glob.get('__name__') or 'unknown'
- print('-- {0} imports {1}'.format(importer_name, name))
- return real_import(name, locals, globals, fromlist, level)
- builtins.__import__ = debug_import
- STATICA_HACK = True
- globals()['kcah_acitats'[::-1].upper()] = False
- if STATICA_HACK: # pragma: no cover
- # This is never executed, but tricks static analyzers (PyDev, PyCharm,
- # pylint, etc.) into knowing the types of these symbols, and what
- # they contain.
- from celery.app import shared_task # noqa
- from celery.app.base import Celery # noqa
- from celery.app.utils import bugreport # noqa
- from celery.app.task import Task # noqa
- from celery._state import current_app, current_task # noqa
- from celery.canvas import ( # noqa
- chain, chord, chunks, group, subtask, xmap, xstarmap,
- )
- from celery.utils import uuid # noqa
- # Lazy loading
- from .five import recreate_module
- old_module, new_module = recreate_module( # pragma: no cover
- __name__,
- by_module={
- 'celery.app': ['Celery', 'bugreport', 'shared_task'],
- 'celery.app.task': ['Task'],
- 'celery._state': ['current_app', 'current_task'],
- 'celery.canvas': ['chain', 'chord', 'chunks', 'group',
- 'subtask', 'xmap', 'xstarmap'],
- 'celery.utils': ['uuid'],
- },
- direct={'task': 'celery.task'},
- __package__='celery', __file__=__file__,
- __path__=__path__, __doc__=__doc__, __version__=__version__,
- __author__=__author__, __contact__=__contact__,
- __homepage__=__homepage__, __docformat__=__docformat__,
- VERSION=VERSION, SERIES=SERIES, VERSION_BANNER=VERSION_BANNER,
- )
- if sys.version_info[0:2] == (3, 2):
- # There is a problem in Python3's import system where it
- # returns the raw module object instead of the one
- # kept in ``sys.modules``.
- # This breaks our dynamically generated modules because we insert
- # them into sys.modules, and expect the import statement to return
- # that.
- # I'm not entirely sure of why, or when it happens, but this import hook
- # fixes the problem. The bug can be reproduced by disabling the hook
- # and doing the following:
- #
- # >>> import celery
- # >>> from celery.task import sets
- # >>> from celery import task
- # >>> type(celery.task)
- # <class 'celery.task'>
- # >>> import sys
- # >>> import celery
- # >>> sys.modules.pop('celery.task')
- # <module 'celery.task' from 'celery/task/__init__.py'>
- # >>> from celery.task import sets
- # Traceback (most recent call last):
- # File "<stdin>", line 1, in <module>
- # ImportError: cannot import name sets
- # >>> type(celery.task)
- # <class 'module'> # <-- where did this come from?!?
- # Note that popping the module from sys.modules is just a way to force
- # this to happen and I'm sure it happens in other cases too.
- # [ask]
- import imp
- class FixBrokenImportHook(object):
- generated_modules = ('celery', 'celery.task')
- def load_module(self, name, *args):
- try:
- return sys.modules[name]
- except KeyError:
- modname, path = name, None
- if '.' in name:
- modname, path = name.split('.')[-1], __path__
- module_info = imp.find_module(modname, path)
- imp.load_module(name, *module_info)
- return sys.modules[name]
- def find_module(self, name, path):
- if name in self.generated_modules:
- return self
- return None
- sys.meta_path.insert(0, FixBrokenImportHook())
|