浏览代码

Cosmetics

Ask Solem 9 年之前
父节点
当前提交
8de8bb99b2

+ 17 - 13
celery/app/base.py

@@ -39,6 +39,7 @@ from celery.utils import abstract
 from celery.utils import gen_task_name
 from celery.utils.dispatch import Signal
 from celery.utils.functional import first, maybe_list, head_from_fun
+from celery.utils.timeutils import timezone
 from celery.utils.imports import instantiate, symbol_by_name
 from celery.utils.log import get_logger
 from celery.utils.objects import FallbackContext, mro_lookup
@@ -58,7 +59,7 @@ __all__ = ['Celery']
 
 logger = get_logger(__name__)
 
-_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
+USING_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
 BUILTIN_FIXUPS = {
     'celery.fixups.django:fixup',
 }
@@ -89,6 +90,7 @@ def _after_fork_cleanup_app(app):
 
 
 class PendingConfiguration(UserDict, AttributeDictMixin):
+
     callback = None
     data = None
 
@@ -104,7 +106,8 @@ class Celery(object):
     """Celery application.
 
     :param main: Name of the main module if running as `__main__`.
-        This is used as a prefix for task names.
+        This is used as the prefix for autogenerated task names.
+
     :keyword broker: URL of the default broker used.
     :keyword loader: The loader class, or the name of the loader class to use.
                      Default is :class:`celery.loaders.app.AppLoader`.
@@ -145,6 +148,8 @@ class Celery(object):
     #: See :ref:`extending-bootsteps`.
     steps = None
 
+    builtin_fixups = BUILTIN_FIXUPS
+
     amqp_cls = 'celery.app.amqp:AMQP'
     backend_cls = None
     events_cls = 'celery.events:Events'
@@ -153,10 +158,10 @@ class Celery(object):
     control_cls = 'celery.app.control:Control'
     task_cls = 'celery.app.task:Task'
     registry_cls = TaskRegistry
+
     _fixups = None
     _pool = None
     _conf = None
-    builtin_fixups = BUILTIN_FIXUPS
     _after_fork_registered = False
 
     #: Signal sent when app is loading configuration.
@@ -240,6 +245,10 @@ class Celery(object):
         self.on_init()
         _register_app(self)
 
+    def on_init(self):
+        """Optional callback called at init."""
+        pass
+
     def __autoset(self, key, value):
         if value:
             self._preconf[key] = value
@@ -278,10 +287,6 @@ class Celery(object):
         self._pool = None
         _deregister_app(self)
 
-    def on_init(self):
-        """Optional callback called at init."""
-        pass
-
     def start(self, argv=None):
         """Run :program:`celery` using `argv`.
 
@@ -289,8 +294,8 @@ class Celery(object):
 
         """
         return instantiate(
-            'celery.bin.celery:CeleryCommand',
-            app=self).execute_from_commandline(argv)
+            'celery.bin.celery:CeleryCommand', app=self
+        ).execute_from_commandline(argv)
 
     def worker_main(self, argv=None):
         """Run :program:`celery worker` using `argv`.
@@ -299,8 +304,8 @@ class Celery(object):
 
         """
         return instantiate(
-            'celery.bin.worker:worker',
-            app=self).execute_from_commandline(argv)
+            'celery.bin.worker:worker', app=self
+        ).execute_from_commandline(argv)
 
     def task(self, *args, **opts):
         """Decorator to create a task class out of any callable.
@@ -332,7 +337,7 @@ class Celery(object):
             application is fully set up (finalized).
 
         """
-        if _EXECV and opts.get('lazy', True):
+        if USING_EXECV and opts.get('lazy', True):
             # When using execv the task in the original module will point to a
             # different app, so doing things like 'add.request' will point to
             # a different task instance.  This makes sure it will always use
@@ -1127,7 +1132,6 @@ class Celery(object):
         :setting:`timezone` setting.
 
         """
-        from celery.utils.timeutils import timezone
         conf = self.conf
         tz = conf.timezone
         if not tz:

+ 6 - 7
celery/app/control.py

@@ -55,13 +55,12 @@ class Inspect(object):
         self.limit = limit
 
     def _prepare(self, reply):
-        if not reply:
-            return
-        by_node = flatten_reply(reply)
-        if self.destination and \
-                not isinstance(self.destination, (list, tuple)):
-            return by_node.get(self.destination)
-        return by_node
+        if reply:
+            by_node = flatten_reply(reply)
+            if (self.destination and
+                    not isinstance(self.destination, (list, tuple))):
+                return by_node.get(self.destination)
+            return by_node
 
     def _request(self, command, **kwargs):
         return self._prepare(self.app.control.broadcast(

+ 4 - 4
celery/tests/app/test_app.py

@@ -138,7 +138,7 @@ class test_App(AppCase):
 
     @depends_on_current_app
     def test_task_windows_execv(self):
-        prev, _appbase._EXECV = _appbase._EXECV, True
+        prev, _appbase.USING_EXECV = _appbase.USING_EXECV, True
         try:
             @self.app.task(shared=False)
             def foo():
@@ -147,8 +147,8 @@ class test_App(AppCase):
             self.assertTrue(foo._get_current_object())  # is proxy
 
         finally:
-            _appbase._EXECV = prev
-        assert not _appbase._EXECV
+            _appbase.USING_EXECV = prev
+        assert not _appbase.USING_EXECV
 
     def test_task_takes_no_args(self):
         with self.assertRaises(TypeError):
@@ -405,7 +405,7 @@ class test_App(AppCase):
                 check(task)
                 return task
 
-            assert not _appbase._EXECV
+            assert not _appbase.USING_EXECV
 
             @app.task(filter=filter, shared=False)
             def foo():

+ 1 - 1
celery/utils/encoding.py

@@ -6,7 +6,7 @@
     This module has moved to :mod:`kombu.utils.encoding`.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from kombu.utils.encoding import (  # noqa
     default_encode, default_encoding, bytes_t, bytes_to_str, str_t,

+ 2 - 1
celery/utils/functional.py

@@ -6,7 +6,7 @@
     Utilities for functions.
 
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import sys
 import threading
@@ -321,6 +321,7 @@ def regen(it):
 
 class _regen(UserList, list):
     # must be subclass of list so that json can encode.
+
     def __init__(self, it):
         self.__it = it
         self.__index = 0

+ 1 - 1
celery/utils/imports.py

@@ -6,7 +6,7 @@
     Utilities related to importing modules and symbols by name.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import imp as _imp
 import importlib

+ 2 - 3
celery/utils/iso8601.py

@@ -1,5 +1,4 @@
-"""
-Originally taken from pyiso8601 (http://code.google.com/p/pyiso8601/)
+"""Originally taken from pyiso8601 (http://code.google.com/p/pyiso8601/)
 
 Modified to match the behavior of dateutil.parser:
 
@@ -31,7 +30,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import re
 

+ 1 - 1
celery/utils/log.py

@@ -6,7 +6,7 @@
     Logging utilities.
 
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import logging
 import numbers

+ 1 - 1
celery/utils/mail.py

@@ -6,7 +6,7 @@
     How task error emails are formatted and sent.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import smtplib
 import socket

+ 1 - 1
celery/utils/objects.py

@@ -6,7 +6,7 @@
     Object related utilities including introspection, etc.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 __all__ = ['mro_lookup']
 

+ 1 - 1
celery/utils/serialization.py

@@ -6,7 +6,7 @@
     Utilities for safely pickling exceptions.
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from base64 import b64encode as base64encode, b64decode as base64decode
 from inspect import getmro

+ 1 - 1
celery/utils/sysinfo.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import os
 

+ 1 - 1
celery/utils/text.py

@@ -6,7 +6,7 @@
     Text formatting utilities
 
 """
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 from textwrap import fill
 

+ 1 - 1
celery/utils/threads.py

@@ -6,7 +6,7 @@
     Threading utilities.
 
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 import socket

+ 1 - 1
celery/utils/timer2.py

@@ -6,7 +6,7 @@
     Scheduler for Python functions.
 
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 import sys

+ 1 - 1
celery/utils/timeutils.py

@@ -6,7 +6,7 @@
     This module contains various utilities related to dates and times.
 
 """
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import numbers
 import os