Coverage for cedar/config/core.py : 42%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Configuration file handling """
""" CEDAR configuration file """
self._config = config.copy() self.schema = schema or self._load_schema() self.validate()
# Mapping methods return self._config[key]
for key in self._config: yield key
return len(self._config)
# Class create/serialize methods """ Load from a YAML configuration file """ with open(filename) as f: config = yaml.safe_load(f) return cls(config, schema=schema)
""" Load from the included YAML configuration file template """ return cls.from_yaml(TEMPLATE_FILE, schema=schema)
""" Write to a YAML (file, if ``dest`` is provided)
Parameters ---------- dest : str or Path Filename to write to. If not provided, returns a str
Returns ------- str Either the filename written to, or a str containing the YAML data if ``dest`` is ``None`` """ if dest is not None: with open(dest, 'w') as dst: dmp = yaml.safe_dump(self._config, stream=dst, indent=indent, sort_keys=sort_keys, **kwds) return dst else: return yaml.safe_dump(self._config, indent=indent, sort_keys=sort_keys, **kwds)
# Getter-s for various objects this config describes with open(filename) as src: return json.load(src)
""" Validate the configuration against schema
Raises ------ ValidationError Raised if there's an issue """ validation.validate_with_defaults(self._config, schema=self.schema)
""" Get the Tracker described by this store """ # Copy tracker config cfg = self['tracker'].copy()
# Create tile grid tile_grid = self.get_tile_grid()
# Create store service = cfg.pop('store').lower() if service == 'gcs': store = self.get_gcs_store() elif service == 'gdrive': store = self.get_gdrive_store() else: raise ValueError(f'Unknown `store_service` named "{service}"')
# Create tracker tracker = build.build_tracker(tile_grid, store, **cfg) return tracker
""" Return the Tile Grid described by this config
Returns ------- stems.gis.grids.TileGrid """ cfg = self['tile_grid'].copy() grid_name = cfg.pop('grid_name', None) grid_filename = cfg.pop('grid_filename', None) return build.build_tile_grid(grid_name, grid_filename, **cfg)
""" Return a GCSStore described by this config """ from cedar.stores.gcs import GCSStore cfg = self.get('gcs', {}) store = GCS.from_credentials(**kwds) return store
""" Return a GDriveStore described by this config """ from cedar.stores.gdrive import GDriveStore cfg = self.get('gdrive', {}) store = GDriveStore.from_credentials(**cfg) return store |