浏览代码

Task modules are now imported from the current directory

Ask Solem 14 年之前
父节点
当前提交
e636f87c25
共有 2 个文件被更改,包括 23 次插入21 次删除
  1. 23 1
      celery/loaders/base.py
  2. 0 20
      celery/loaders/default.py

+ 23 - 1
celery/loaders/base.py

@@ -1,3 +1,6 @@
+import os
+import sys
+
 from importlib import import_module
 from importlib import import_module
 
 
 BUILTIN_MODULES = ["celery.task"]
 BUILTIN_MODULES = ["celery.task"]
@@ -37,7 +40,7 @@ class BaseLoader(object):
         pass
         pass
 
 
     def import_task_module(self, module):
     def import_task_module(self, module):
-        return self.import_module(module)
+        return self.import_from_cwd(module)
 
 
     def import_module(self, module):
     def import_module(self, module):
         return import_module(module)
         return import_module(module)
@@ -52,6 +55,25 @@ class BaseLoader(object):
             self.worker_initialized = True
             self.worker_initialized = True
             self.on_worker_init()
             self.on_worker_init()
 
 
+    def import_from_cwd(self, module, imp=import_module):
+        """Import module, but make sure it finds modules
+        located in the current directory.
+
+        Modules located in the current directory has
+        precedence over modules located in ``sys.path``.
+        """
+        cwd = os.getcwd()
+        if cwd in sys.path:
+            return imp(module)
+        sys.path.insert(0, cwd)
+        try:
+            return imp(module)
+        finally:
+            try:
+                sys.path.remove(cwd)
+            except ValueError:          # pragma: no cover
+                pass
+
     @property
     @property
     def conf(self):
     def conf(self):
         """Loader configuration."""
         """Loader configuration."""

+ 0 - 20
celery/loaders/default.py

@@ -1,5 +1,4 @@
 import os
 import os
-import sys
 import warnings
 import warnings
 from importlib import import_module
 from importlib import import_module
 
 
@@ -47,25 +46,6 @@ class Loader(BaseLoader):
 
 
         return settings
         return settings
 
 
-    def import_from_cwd(self, module, imp=import_module):
-        """Import module, but make sure it finds modules
-        located in the current directory.
-
-        Modules located in the current directory has
-        precedence over modules located in ``sys.path``.
-        """
-        cwd = os.getcwd()
-        if cwd in sys.path:
-            return imp(module)
-        sys.path.insert(0, cwd)
-        try:
-            return imp(module)
-        finally:
-            try:
-                sys.path.remove(cwd)
-            except ValueError:          # pragma: no cover
-                pass
-
     def read_configuration(self):
     def read_configuration(self):
         """Read configuration from ``celeryconfig.py`` and configure
         """Read configuration from ``celeryconfig.py`` and configure
         celery and Django so it can be used by regular Python."""
         celery and Django so it can be used by regular Python."""