def configs_for_reader(reader=None, ppp_config_dir=None): """Generator of reader configuration files for one or more readers Args: reader (Optional[str]): Yield configs only for this reader ppp_config_dir (Optional[str]): Additional configuration directory to search for reader configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir, ) if ppp_config_dir else tuple() if reader is not None: if not isinstance(reader, (list, tuple)): reader = [reader] # given a config filename or reader name config_files = [ r if r.endswith('.yaml') else r + '.yaml' for r in reader ] else: reader_configs = glob_config(os.path.join('readers', '*.yaml'), *search_paths) config_files = set(reader_configs) for config_file in config_files: config_basename = os.path.basename(config_file) reader_configs = config_search_paths( os.path.join("readers", config_basename), *search_paths) if not reader_configs: # either the reader they asked for does not exist # or satpy is improperly configured and can't find its own readers raise ValueError("No reader(s) named: {}".format(reader)) yield reader_configs
def configs_for_reader(reader=None, ppp_config_dir=None): """Generator of reader configuration files for one or more readers Args: reader (Optional[str]): Yield configs only for this reader ppp_config_dir (Optional[str]): Additional configuration directory to search for reader configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir, ) if ppp_config_dir else tuple() if reader is not None: if not isinstance(reader, (list, tuple)): reader = [reader] # given a config filename or reader name config_files = [ r if r.endswith('.yaml') else r + '.yaml' for r in reader ] else: reader_configs = glob_config(os.path.join('readers', '*.yaml'), *search_paths) config_files = set(reader_configs) for config_file in config_files: config_basename = os.path.basename(config_file) reader_configs = config_search_paths( os.path.join("readers", config_basename), *search_paths) if not reader_configs: LOG.warning("No reader configs found for '%s'", reader) continue yield reader_configs
def configs_for_writer(writer=None, ppp_config_dir=None): """Generate writer configuration files for one or more writers. Args: writer (Optional[str]): Yield configs only for this writer ppp_config_dir (Optional[str]): Additional configuration directory to search for writer configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir, ) if ppp_config_dir else tuple() if writer is not None: if not isinstance(writer, (list, tuple)): writer = [writer] # given a config filename or writer name config_files = [ w if w.endswith('.yaml') else w + '.yaml' for w in writer ] else: writer_configs = glob_config(os.path.join('writers', '*.yaml'), *search_paths) config_files = set(writer_configs) for config_file in config_files: config_basename = os.path.basename(config_file) writer_configs = config_search_paths( os.path.join("writers", config_basename), *search_paths) if not writer_configs: LOG.warning("No writer configs found for '%s'", writer) continue yield writer_configs
def configs_for_reader(reader=None, ppp_config_dir=None): """Generator of reader configuration files for one or more readers Args: reader (Optional[str]): Yield configs only for this reader ppp_config_dir (Optional[str]): Additional configuration directory to search for reader configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir,) if ppp_config_dir else tuple() if reader is not None: if not isinstance(reader, (list, tuple)): reader = [reader] # given a config filename or reader name config_files = [r if r.endswith('.yaml') else r + '.yaml' for r in reader] else: reader_configs = glob_config(os.path.join('readers', '*.yaml'), *search_paths) config_files = set(reader_configs) for config_file in config_files: config_basename = os.path.basename(config_file) reader_configs = config_search_paths( os.path.join("readers", config_basename), *search_paths) if not reader_configs: LOG.warning("No reader configs found for '%s'", reader) continue yield reader_configs
def configs_for_writer(writer=None, ppp_config_dir=None): """Generator of writer configuration files for one or more writers Args: writer (Optional[str]): Yield configs only for this writer ppp_config_dir (Optional[str]): Additional configuration directory to search for writer configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir,) if ppp_config_dir else tuple() if writer is not None: if not isinstance(writer, (list, tuple)): writer = [writer] # given a config filename or writer name config_files = [w if w.endswith('.yaml') else w + '.yaml' for w in writer] else: writer_configs = glob_config(os.path.join('writers', '*.yaml'), *search_paths) config_files = set(writer_configs) for config_file in config_files: config_basename = os.path.basename(config_file) writer_configs = config_search_paths( os.path.join("writers", config_basename), *search_paths) if not writer_configs: LOG.warning("No writer configs found for '%s'", writer) continue yield writer_configs
def configs_for_reader(reader=None, ppp_config_dir=None): """Generator of reader configuration files for one or more readers Args: reader (Optional[str]): Yield configs only for this reader ppp_config_dir (Optional[str]): Additional configuration directory to search for reader configuration files. Returns: Generator of lists of configuration files """ search_paths = (ppp_config_dir, ) if ppp_config_dir else tuple() if reader is not None: if not isinstance(reader, (list, tuple)): reader = [reader] # check for old reader names new_readers = [] for reader_name in reader: if reader_name.endswith( '.yaml') or reader_name not in OLD_READER_NAMES: new_readers.append(reader_name) continue new_name = OLD_READER_NAMES[reader_name] # SatPy 0.11 only displays a warning warnings.warn( "Reader name '{}' has been deprecated, use '{}' instead.". format(reader_name, new_name), DeprecationWarning) # SatPy 0.12 will raise an exception # raise ValueError("Reader name '{}' has been deprecated, use '{}' instead.".format(reader_name, new_name)) # SatPy 0.13 or 1.0, remove exception and mapping new_readers.append(new_name) reader = new_readers # given a config filename or reader name config_files = [ r if r.endswith('.yaml') else r + '.yaml' for r in reader ] else: reader_configs = glob_config(os.path.join('readers', '*.yaml'), *search_paths) config_files = set(reader_configs) for config_file in config_files: config_basename = os.path.basename(config_file) reader_configs = config_search_paths( os.path.join("readers", config_basename), *search_paths) if not reader_configs: # either the reader they asked for does not exist # or satpy is improperly configured and can't find its own readers raise ValueError("No reader(s) named: {}".format(reader)) yield reader_configs
def test_filename_matches_reader_name(self): """Test that every reader filename matches the name in the YAML.""" import yaml class IgnoreLoader(yaml.SafeLoader): def _ignore_all_tags(self, tag_suffix, node): return tag_suffix + ' ' + node.value IgnoreLoader.add_multi_constructor('', IgnoreLoader._ignore_all_tags) from satpy.config import glob_config from satpy.readers import read_reader_config for reader_config in glob_config('readers/*.yaml'): reader_fn = os.path.basename(reader_config) reader_fn_name = os.path.splitext(reader_fn)[0] reader_info = read_reader_config([reader_config], loader=IgnoreLoader) self.assertEqual(reader_fn_name, reader_info['name'], "Reader YAML filename doesn't match reader " "name in the YAML file.")
def test_filename_matches_reader_name(self): """Test that every reader filename matches the name in the YAML.""" import yaml class IgnoreLoader(yaml.SafeLoader): def _ignore_all_tags(self, tag_suffix, node): return tag_suffix + ' ' + node.value IgnoreLoader.add_multi_constructor('', IgnoreLoader._ignore_all_tags) from satpy.config import glob_config from satpy.readers import read_reader_config for reader_config in glob_config('readers/*.yaml'): reader_fn = os.path.basename(reader_config) reader_fn_name = os.path.splitext(reader_fn)[0] reader_info = read_reader_config([reader_config], loader=IgnoreLoader) self.assertEqual(reader_fn_name, reader_info['name'], "Reader YAML filename doesn't match reader " "name in the YAML file.")
def config_files(self): return glob_config( os.path.join("readers", "*.yaml"), self.ppp_config_dir)
def config_files(self): return glob_config(os.path.join("readers", "*.yaml"), self.ppp_config_dir)