فهرست منبع

Allows CELERY_IMPORTS to be a scalar value.

It is too easy to forget to add the comma after the sole element of a tuple,
and this is something that often bites newcomers.

The docs should probably use a list in examples, as using a tuple
for this doesn't even make sense.  Nontheless, there are many
tutorials out there using a tuple, and this should be helpful
to new users.

Closes #485.  Thanks to jsaxon-cars.
Ask Solem 13 سال پیش
والد
کامیت
b164497964
2فایلهای تغییر یافته به همراه14 افزوده شده و 1 حذف شده
  1. 2 1
      celery/loaders/base.py
  2. 12 0
      celery/utils/functional.py

+ 2 - 1
celery/loaders/base.py

@@ -11,6 +11,7 @@ from ..datastructures import DictAttribute
 from ..exceptions import ImproperlyConfigured
 from ..exceptions import ImproperlyConfigured
 from ..utils import (cached_property, get_cls_by_name,
 from ..utils import (cached_property, get_cls_by_name,
                      import_from_cwd as _import_from_cwd)
                      import_from_cwd as _import_from_cwd)
+from ..utils.functional import maybe_list
 
 
 BUILTIN_MODULES = frozenset(["celery.task"])
 BUILTIN_MODULES = frozenset(["celery.task"])
 
 
@@ -74,7 +75,7 @@ class BaseLoader(object):
                 package=package)
                 package=package)
 
 
     def import_default_modules(self):
     def import_default_modules(self):
-        imports = set(list(self.conf.get("CELERY_IMPORTS") or ()))
+        imports = set(maybe_list(self.conf.get("CELERY_IMPORTS") or ()))
         return [self.import_task_module(module)
         return [self.import_task_module(module)
                     for module in imports | self.builtin_modules]
                     for module in imports | self.builtin_modules]
 
 

+ 12 - 0
celery/utils/functional.py

@@ -3,11 +3,23 @@ from __future__ import absolute_import, with_statement
 from functools import wraps
 from functools import wraps
 from threading import Lock
 from threading import Lock
 
 
+try:
+    from collections import Sequence
+except ImportError:  # noqa
+    # <= Py2.5
+    Sequence = (list, tuple)
+
 from celery.datastructures import LRUCache
 from celery.datastructures import LRUCache
 
 
 KEYWORD_MARK = object()
 KEYWORD_MARK = object()
 
 
 
 
+def maybe_list(l):
+    if isinstance(l, Sequence):
+        return l
+    return [l]
+
+
 def memoize(maxsize=None, Cache=LRUCache):
 def memoize(maxsize=None, Cache=LRUCache):
 
 
     def _memoize(fun):
     def _memoize(fun):