def _require(key, cfg, error_msg=None):
    """ Ensures that `key` is in the config `cfg`. """
    error_msg = error_msg or f'Missing field `{key}` in the config file.'
    val = cfg.get(key)
    if not val:
        raise ValueError(error_msg)
    return val