def test_old_path_gets_fixed(self): with warnings.catch_warnings(record=True) as w: output = update_classpath('scrapy.contrib.debug.Debug') self.assertEqual(output, 'scrapy.extensions.debug.Debug') self.assertEqual(len(w), 1) self.assertIn("scrapy.contrib.debug.Debug", str(w[0].message)) self.assertIn("scrapy.extensions.debug.Debug", str(w[0].message))
def update_deprecated_classpaths(settings): # This method updates settings with dicts as values if they're deprecated for setting_key in settings.attributes.keys(): setting_value = settings[setting_key] if hasattr(setting_value, "copy_to_dict"): setting_value = setting_value.copy_to_dict() if not isinstance(setting_value, dict): continue for path in setting_value.keys(): updated_path = update_classpath(path) if updated_path != path: order = settings[setting_key].pop(path) settings[setting_key][updated_path] = order
def _load_addons(addons, s, o): for addon in addons: if addon['path'].startswith('hworker'): try: import hworker except ImportError: continue # ignore missing module skey = _get_component_base(s, addon['type']) components = s[skey] path = update_classpath(addon['path']) components[path] = addon['order'] o[skey] = components _update_settings(o, addon['default_settings'])
def _update_old_classpaths(settings): """Update user's project settings with proper class paths. Note that the method updates only settings with dicts as values: it's needed for proper dicts merge to avoid duplicates in paths. For all other cases Scrapy will handle it by itself. """ for setting_key in settings.attributes.keys(): setting_value = settings[setting_key] # A workaround to make it work for: # - Scrapy==1.0.5 with dicts as values # - Scrapy>=1.1.0 with BaseSettings as values if hasattr(setting_value, 'copy_to_dict'): setting_value = setting_value.copy_to_dict() elif not isinstance(setting_value, dict): continue for path in setting_value.keys(): if not is_string(path): continue updated_path = update_classpath(path) if updated_path != path: order = settings[setting_key].pop(path) settings[setting_key][updated_path] = order
def _update_component_order(components, path, order): """Update component order only if it's not set yet""" updated_path = update_classpath(path) if updated_path not in components: components[updated_path] = order
def test_unmatched_path_stays_the_same(self): with warnings.catch_warnings(record=True) as w: output = update_classpath('scrapy.unmatched.Path') self.assertEqual(output, 'scrapy.unmatched.Path') self.assertEqual(len(w), 0)
def test_sorted_replacement(self): with warnings.catch_warnings(): warnings.simplefilter('ignore', ScrapyDeprecationWarning) output = update_classpath('scrapy.contrib.pipeline.Pipeline') self.assertEqual(output, 'scrapy.pipelines.Pipeline')
def test_sorted_replacement(self): with warnings.catch_warnings(record=True): output = update_classpath('scrapy.contrib.pipeline.Pipeline') self.assertEqual(output, 'scrapy.pipelines.Pipeline')