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)
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)
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)
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)
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
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()
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)
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)