Exemplo n.º 1
0
 def read_configuration(self):
     """Read configuration from :file:`celeryconfig.py` and configure
     celery and Django so it can be used by regular Python."""
     configname = os.environ.get("CELERY_CONFIG_MODULE",
                                 DEFAULT_CONFIG_MODULE)
     try:
         self.find_module(configname)
     except NotAPackage:
         if configname.endswith('.py'):
             raise NotAPackage, NotAPackage(CONFIG_WITH_SUFFIX % {
                 "module": configname,
                 "suggest": configname[:-3]
             }), sys.exc_info()[2]
         raise NotAPackage, NotAPackage(
             CONFIG_INVALID_NAME %
             {"module": configname}), sys.exc_info()[2]
     except ImportError:
         warnings.warn(
             NotConfigured(
                 "No %r module found! Please make sure it exists and "
                 "is available to Python." % (configname, )))
         return self.setup_settings({})
     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
         return self.setup_settings(usercfg)
Exemplo n.º 2
0
 def read_configuration(self):
     """Read configuration from :file:`celeryconfig.py` and configure
     celery and Django so it can be used by regular Python."""
     configname = os.environ.get('CELERY_CONFIG_MODULE',
                                  DEFAULT_CONFIG_MODULE)
     try:
         self.find_module(configname)
     except NotAPackage:
         if configname.endswith('.py'):
             raise NotAPackage, NotAPackage(
                     CONFIG_WITH_SUFFIX % {
                         'module': configname,
                         'suggest': configname[:-3]}), sys.exc_info()[2]
         raise NotAPackage, NotAPackage(
                 CONFIG_INVALID_NAME % {
                     'module': configname}), sys.exc_info()[2]
     except ImportError:
         # billiard sets this if forked using execv
         if C_WNOCONF and not os.environ.get('FORKED_BY_MULTIPROCESSING'):
             warnings.warn(NotConfigured(
                 'No %r module found! Please make sure it exists and '
                 'is available to Python.' % (configname, )))
         return self.setup_settings({})
     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
         return self.setup_settings(usercfg)
Exemplo n.º 3
0
Arquivo: base.py Projeto: mahak/celery
 def _import_config_module(self, name):
     try:
         self.find_module(name)
     except NotAPackage as exc:
         if name.endswith('.py'):
             reraise(NotAPackage, NotAPackage(CONFIG_WITH_SUFFIX.format(
                     module=name, suggest=name[:-3])), sys.exc_info()[2])
         raise NotAPackage(CONFIG_INVALID_NAME.format(module=name)) from exc
     else:
         return self.import_from_cwd(name)
Exemplo n.º 4
0
 def _import_config_module(self, name):
     try:
         self.find_module(name)
     except NotAPackage:
         if name.endswith('.py'):
             raise NotAPackage, NotAPackage(CONFIG_WITH_SUFFIX % {
                 'module': name, 'suggest': name[:-3]}), sys.exc_info()[2]
         raise NotAPackage, NotAPackage(
             CONFIG_INVALID_NAME % {'module': name}), sys.exc_info()[2]
     else:
         return self.import_from_cwd(name)
Exemplo n.º 5
0
 def test_read_configuration_py_in_name(self, find_module):
     prev = os.environ['CELERY_CONFIG_MODULE']
     os.environ['CELERY_CONFIG_MODULE'] = 'celeryconfig.py'
     try:
         find_module.side_effect = NotAPackage()
         l = default.Loader(app=self.app)
         with self.assertRaises(NotAPackage):
             l.read_configuration()
     finally:
         os.environ['CELERY_CONFIG_MODULE'] = prev
Exemplo n.º 6
0
 def test_read_configuration_not_a_package(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with self.assertRaises(NotAPackage):
         l.read_configuration()
Exemplo n.º 7
0
 def test_read_configuration_py_in_name(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with self.assertRaises(NotAPackage):
         l.read_configuration(fail_silently=False)
Exemplo n.º 8
0
 def test_read_configuration_not_a_package(self, find_module):
     find_module.side_effect = NotAPackage()
     l = default.Loader(app=self.app)
     with pytest.raises(NotAPackage):
         l.read_configuration(fail_silently=False)