def __init__(self, path='.'): self.inside_project = False self.cfg_path = self.get_closest_cfg(path=path) self.cfg = None self.project_dir = None self.module_settings = Settings() # user-defined settings file self._data_dir = None if self.cfg_path: # init project dir self.project_dir = os.path.dirname(self.cfg_path) if self.project_dir not in sys.path: sys.path.append(self.project_dir) # init cfg self.cfg = SafeConfigParser() self.cfg.read([self.cfg_path]) # init settings if self.cfg.has_option('crawlmi', 'settings'): settings_module_path = self.cfg.get('crawlmi', 'settings') try: settings_module = __import__(settings_module_path, {}, {}, ['']) except ImportError as exc: warnings.warn( 'Cannot import crawlmi settings module %s: %s' % (settings_module_path, exc)) else: self.module_settings = Settings.from_module(settings_module) self.inside_project = True
def __init__(self, path='.'): self.inside_project = False self.cfg_path = self.get_closest_cfg(path=path) self.cfg = None self.project_dir = None self.module_settings = Settings() # user-defined settings file self._data_dir = None if self.cfg_path: # init project dir self.project_dir = os.path.dirname(self.cfg_path) if self.project_dir not in sys.path: sys.path.append(self.project_dir) # init cfg self.cfg = SafeConfigParser() self.cfg.read([self.cfg_path]) # init settings if self.cfg.has_option('crawlmi', 'settings'): settings_module_path = self.cfg.get('crawlmi', 'settings') try: settings_module = __import__(settings_module_path, {}, {}, ['']) except ImportError as exc: warnings.warn( 'Cannot import crawlmi settings module %s: %s' % (settings_module_path, exc)) else: self.module_settings = Settings.from_module( settings_module) self.inside_project = True
def test_from_module(self): s = Settings.from_module('crawlmi.settings.default_settings') self.assertIn('CONCURRENT_REQUESTS', s) self.assertNotIn('blabla', s) self.assertNotIn('__name__', s)