|
@@ -9,13 +9,11 @@
|
|
from __future__ import absolute_import
|
|
from __future__ import absolute_import
|
|
|
|
|
|
import os
|
|
import os
|
|
-import sys
|
|
|
|
import warnings
|
|
import warnings
|
|
|
|
|
|
-from celery.datastructures import AttributeDict
|
|
|
|
|
|
+from celery.datastructures import DictAttribute
|
|
from celery.exceptions import NotConfigured
|
|
from celery.exceptions import NotConfigured
|
|
from celery.utils import strtobool
|
|
from celery.utils import strtobool
|
|
-from celery.utils.imports import NotAPackage, find_module
|
|
|
|
|
|
|
|
from .base import BaseLoader
|
|
from .base import BaseLoader
|
|
|
|
|
|
@@ -24,24 +22,12 @@ DEFAULT_CONFIG_MODULE = 'celeryconfig'
|
|
#: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set.
|
|
#: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set.
|
|
C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False))
|
|
C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False))
|
|
|
|
|
|
-CONFIG_INVALID_NAME = """
|
|
|
|
-Error: Module '{module}' doesn't exist, or it's not a valid \
|
|
|
|
-Python module name.
|
|
|
|
-"""
|
|
|
|
-
|
|
|
|
-CONFIG_WITH_SUFFIX = CONFIG_INVALID_NAME + """
|
|
|
|
-Did you mean '{suggest}'?
|
|
|
|
-"""
|
|
|
|
-
|
|
|
|
|
|
|
|
class Loader(BaseLoader):
|
|
class Loader(BaseLoader):
|
|
"""The loader used by the default app."""
|
|
"""The loader used by the default app."""
|
|
|
|
|
|
def setup_settings(self, settingsdict):
|
|
def setup_settings(self, settingsdict):
|
|
- return AttributeDict(settingsdict)
|
|
|
|
-
|
|
|
|
- def find_module(self, module):
|
|
|
|
- return find_module(module)
|
|
|
|
|
|
+ return DictAttribute(settingsdict)
|
|
|
|
|
|
def read_configuration(self):
|
|
def read_configuration(self):
|
|
"""Read configuration from :file:`celeryconfig.py` and configure
|
|
"""Read configuration from :file:`celeryconfig.py` and configure
|
|
@@ -49,16 +35,7 @@ class Loader(BaseLoader):
|
|
configname = os.environ.get('CELERY_CONFIG_MODULE',
|
|
configname = os.environ.get('CELERY_CONFIG_MODULE',
|
|
DEFAULT_CONFIG_MODULE)
|
|
DEFAULT_CONFIG_MODULE)
|
|
try:
|
|
try:
|
|
- self.find_module(configname)
|
|
|
|
- except NotAPackage:
|
|
|
|
- if configname.endswith('.py'):
|
|
|
|
- raise NotAPackage, NotAPackage(
|
|
|
|
- CONFIG_WITH_SUFFIX.format(
|
|
|
|
- module=configname,
|
|
|
|
- suggest=configname[:-3])), sys.exc_info()[2]
|
|
|
|
- raise NotAPackage, NotAPackage(
|
|
|
|
- CONFIG_INVALID_NAME.format(
|
|
|
|
- module=configname)), sys.exc_info()[2]
|
|
|
|
|
|
+ usercfg = self._import_config_module(configname)
|
|
except ImportError:
|
|
except ImportError:
|
|
# billiard sets this if forked using execv
|
|
# billiard sets this if forked using execv
|
|
if C_WNOCONF and not os.environ.get('FORKED_BY_MULTIPROCESSING'):
|
|
if C_WNOCONF and not os.environ.get('FORKED_BY_MULTIPROCESSING'):
|
|
@@ -67,12 +44,5 @@ class Loader(BaseLoader):
|
|
'is available to Python.'.format(module=configname)))
|
|
'is available to Python.'.format(module=configname)))
|
|
return self.setup_settings({})
|
|
return self.setup_settings({})
|
|
else:
|
|
else:
|
|
- celeryconfig = self.import_from_cwd(configname)
|
|
|
|
- usercfg = dict((key, getattr(celeryconfig, key))
|
|
|
|
- for key in dir(celeryconfig)
|
|
|
|
- if self.wanted_module_item(key))
|
|
|
|
self.configured = True
|
|
self.configured = True
|
|
return self.setup_settings(usercfg)
|
|
return self.setup_settings(usercfg)
|
|
-
|
|
|
|
- def wanted_module_item(self, item):
|
|
|
|
- return not item.startswith('_')
|
|
|